QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 64 MB مجموع النقاط: 50

#13744. Baza

الإحصائيات

Mirko 在一家大型 IT 公司找到了暑期实习。这家公司构建了一个由 $N$ 行和 $M$ 列组成的大型数据库。

在第一天,Mirko 收到了一共 $Q$ 个查询。每个查询由 $M$ 个数字组成。然而,有些数字在传输过程中丢失了,因此用 $-1$ 表示。Mirko 想知道数据库中有多少行与查询相匹配,即在忽略 $-1$ 的情况下,数据库中有多少行与查询中的数字完全相同。

例如,如果查询的形式为 -1 3 2,那么我们需要统计数据库中满足以下条件的行数:第一列可以是任意数字,第二列的数字为 $3$,且第三列的数字为 $2$。

由于他刚刚开始实习,Mirko 需要你的帮助。帮帮他并回答这些查询吧!

输入格式

第一行输入包含两个整数 $N$ ($1 \le N \le 10^3$) 和 $M$ ($1 \le M \le 10^3$),表示数据库的大小。

接下来的 $N$ 行,每行包含 $M$ 个整数 $A_{ij}$ ($1 \le A_{ij} \le 10^6$),表示数据库的内容。

下一行包含一个整数 $Q$ ($1 \le Q \le 50$),表示查询的数量。

接下来的 $Q$ 行,每行包含 $M$ 个整数 $B_{ij}$ ($B_{ij} = -1$ 或 $1 \le B_{ij} \le 10^6$),表示第 $i$ 个查询的描述。

输出格式

输出应包含 $Q$ 行,每行包含一个整数 $X$,表示对应查询的答案。

样例

输入样例 1

4 3
1 5 2
2 3 4
4 3 2
5 4 6
3
-1 -1 2
-1 3 2
-1 -1 -1

输出样例 1

2
1
4

输入样例 2

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

2
1
0

说明

样例 1 说明

第一个查询询问有多少行在第三列的数字为 $2$。这些行是第 $1$ 行(1 5 2)和第 $3$ 行(4 3 2)。

第二个查询询问有多少行在第二列和第三列的数字分别为 $3$ 和 $2$。这只有第 $3$ 行(4 3 2)。

第三个查询询问总共有多少行,答案显然是 $4$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.