400916: GYM100283 J Anniversary Gift

Memory Limit:256 MB Time Limit:10 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

J. Anniversary Gifttime limit per test10 secondsmemory limit per test256 megabytesinputgift.inoutputstandard output

2 years have passed now since Bakkar's graduation. He has completed his military service period and happily got married to Maymona. Next week is Bakkar & Maymona's anniversary and fortunately Bakkar has a gift in mind for Maymona. He wants to buy her a new smartphone as hers was stolen on her way home in the metro.

Bakkar wants to make Maymona happy as much as he can. So a couple days ago he had a conversation with her about her preferable specs in a smartphone. He noticed that Maymona cares the most about the following four properties: height, width, thickness and weight.

Bakkar also has a very important fifth property which is the price of the smartphone. So Bakkar started to search the internet for the available smartphones. He was shocked by the variety of smartphones available (up to 10,000 phones). So Bakkar started filtering the phones list to get only the phones that satisfies the four properties that Maymona cares about while taking into consideration the price range. His goal now is to find how many smartphones match these criteria so he can take other hints from Maymona to further filter them. Given Maymona's preference ranges for the 4 properties that she cares about, Bakkar's price range that he can afford and a list of available phones each with its corresponding properties (height, width, thickness, weight and price), Bakkar as a Software Engineer will write a short program to filter the list of the smartphones to match Maymona's and his preferences. The program will output the number of smartphones that matches their preferences.

Input

Your program will be tested on one or more test cases. The first line of the input will be a single integer T, the number of test cases (1  ≤  T  ≤  50). Followed by T test cases. The first line of each testcase contains two integer N and Q, the number of smartphones and the number of queries respectively(1  ≤  N,Q  ≤  104).

N lines follow, each line represents the properties of a single phone. Each one containing 5 floating point numbers p, h, w, t, we, representing the price, height, width, thickness and weight. Each number will have at most 3 decimal places. (0.000  ≤  p, h, w, t, we  ≤  5000.000). For each test case, there is no more than 10 different values for each of the price, height, width, thickness and weight.

Q lines follow, each line representing a query. Each one containing 10 floating point numbers p_low, h_low, w_low, t_low, we_low, p_hi, h_hi, w_hi, t_hi, we_hi, representing the lower and upper bounds of the properties. Each number will have at most 3 decimal places. (0.000  ≤  p_low, h_low, w_low, t_low, we_low, p_hi, h_hi, w_hi, t_hi, we_hi,  ≤  5000.000). p_low  ≤  p_hi; h_low  ≤  h_hi; w_low  ≤  w_hi; t_low  ≤  t_hi; we_low  ≤  we_hi.

Output

For each test case print a line containing "Case n:" (without the quotes) where n is the test case number (starting from 1) followed by Q lines, each line contains a single integer, the number of smartphones that matches the query's preferences. A phone matches the query if and only if its value in every property lies between the lower and upper bounds of the query preference inclusive.

ExamplesInput
1
10 3
5.0 6.0 6.0 5.0 4.0
1.0 9.0 3.0 8.0 0.0
1.0 7.0 7.0 5.0 5.0
4.0 0.0 1.0 9.0 8.0
6.0 0.0 5.0 6.0 0.0
6.0 7.0 6.0 5.0 4.0
1.0 4.0 5.0 6.0 6.0
5.0 7.0 8.0 9.0 8.0
1.0 3.0 3.0 7.0 9.0
1.0 2.0 8.0 4.0 8.0
0.0 1.0 2 3.0 4 5.0 6.0 7.0 8.0 9.0
4.0 0.0 1.0 5 0.0 6.0 7.0 6 9.0 8.0
3.0 2.0 5 7.0 8.0 5.0 5.0 6 8.0 9.0
Output
Case 1:
3
4
0
Note

Warning: large Input/Output data, be careful with certain languages.

加入题单

上一题 下一题 算法标签: