Kyle is a student of Programming Monkey Elementary School. Just as others, he is deeply concerned with his grades.
Last month, the school held an examination including five subjects, without any doubt, Kyle got a perfect score in every single subject.
There are n students took part in this examination(not including Kyle), and everyone got an integer between 1 to m as the score of one subject.
Now, looking at the grade table of these n students, Kyle wants to know how many students still did no better than him even if his scores are something else – Here, “no better” means there is no subject in which the student got strictly greater score than Kyle.
There are multiple test cases.
The first line of the input contains an integer T (T <= 3) which means the number of test cases.
The first line of each test case contains two integers, n, m(n, m≤ 50,000), which are the number of students and the perfect score of each subject.
In the next n lines, each line consists of five integers, indicating a student’s scores.
Then one line follows. This line contains an integer q(q≤ 50,000) indicating the number of queries.
In the next q lines, each line contains five integers as well, representing a query. Each query indicates a set of scores, and for each query, you should figure out that if Kyle's grade is this set of scores, how many students still did no better than him. But for the sake of security, only the first query is in its original form, and other queries are encrypted. To decrypt a query, you must let each integer in the query do xor operation with the answer of last query. It's guaranteed that all the decrypted queries contain integers between 1 and 50000.
For each test case, you should output q lines as the answer for all queries.
In case 1, there are two students with different scores and the scores of the first student (1, 1, 1, 1, 1) are not larger than the first query (1 1 1 1 1) in every subject, so the answer for this query is 1.
After having xor operation with the last answer 1, the second query (3,3,3,3,3) will be decrypted into (2, 2, 2, 2, 2). Because both students’ scores are no better than (2, 2, 2, 2, 2), so the answer for query 2 is 2.
2 2 3 1 1 1 1 1 2 2 2 2 2 2 1 1 1 1 1 3 3 3 3 3 3 5 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 2 1 1 1 1 1 1 1 1 1 1样例输出
1 2 2 2解题报告: 求五维皆小于的数量。使用bitset记录当前某个维度,分数不大于给定查询的序号,最终对5个维度的bitset进行与操作。因为查询数量较多,故可以分段预处理。复杂度为O(n * sqrt(n) * M),M为bitset与操作的常数复杂度。样例很少,所以AC还是可以的。代码如下:
#include
#include
#include
#include
#include
#include
#include
#include