#P8038. [COCI 2016/2017 #7] BAZA
[COCI 2016/2017 #7] BAZA
Problem Description
Mirko got a summer internship at a large IT company. The company built a large database with rows and columns, where the integer in row and column is .
On his first day of work, he received queries, and each query contains integers . Unfortunately, some numbers were lost during transmission, and the database replaced them with . Mirko needs to answer how many rows in the database match all the numbers in the query. Formally, Mirko needs to find how many integers in the range satisfy that for all , either or . For example, if and a query is , then Mirko needs to find the number of rows where the first column can be any integer, the second column is , and the third column is .
Since Mirko is new to the internship, he hopes to get your help. Please help him answer these queries.
Input Format
The first line contains two integers , representing the number of rows and columns of the database.
The next lines each contain integers, describing the database.
The next line contains an integer , representing the number of queries.
The next lines each contain integers, describing one query.
Output Format
For each query, output one integer per line, representing the number of rows that satisfy the requirements.
4 3
1 5 2
2 3 4
4 3 2
5 4 6
3
-1 -1 2
-1 3 2
-1 -1 -1
2
1
4
3 8
6 5 97 99 82 50 95 1
85 62 11 64 94 84 88 19
43 99 11 64 94 84 31 19
3
-1 -1 11 64 94 84 -1 19
-1 -1 -1 99 -1 -1 -1 1
95 -1 -1 -1 -1 80 -1 -1
2
1
0
Hint
[Sample 1 Explanation]
For the first query, the first row and the third row satisfy the requirement that the third column is .
For the second query, only the third row satisfies the requirement that the second column is and the third column is .
For the third query, since no column value is required, all rows satisfy the requirements.
[Constraints]
For all testdata, , , , and or .
[Source]
This problem is from COCI 2016-2017 CONTEST 7 T1 BAZA. Using the original testdata configuration, the full score is points.
Translated and organized by Eason_AC.
Translated by ChatGPT 5