QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#22493. 讀書會

Statistics

Bessie 正在為讀書會尋找成員。牛群有 $N$($2 \le N \le 50,000$)頭乳牛,編號為 $1\ldots N$,但她只想招收最有鑑賞力、最善於社交的乳牛。

於是,她像交友服務一樣製作了問卷,讓 $N$ 頭乳牛各自回答 $NQ$($1 \le NQ \le 50$)道題,題目名為 $R_{1}\ldots R_{NQ}$。題目例如「你有多喜歡閱讀科幻小說?」,每個答案是 $1\ldots 5$ 範圍內的整數。

你要統計問卷結果,回答這樣的簡單問題:「有多少頭乳牛在第 3 題回答 2、第 7 題回答 4,並且第 8 題回答 1?」問題含 $P$($1 \le P \le 10$)個條件,每個條件有 $Qj$($1 \le Qj \le NQ$)和 $Aj$($1 \le Aj \le 5$),分別表示題號與要求的答案。程式輸出一個整數,表示對所有 $j\in\{1,\ldots,P\}$ 都在 $Qj$ 題回答 $Aj$ 的乳牛總數。

考慮只有 4 頭乳牛和 5 道題的問卷,答案如下:

乳牛 / 題號 $1$ $2$ $3$ $4$ $5$
$1$ $1$ $1$ $1$ $1$ $1$
$2$ $1$ $2$ $3$ $4$ $5$
$3$ $1$ $2$ $1$ $2$ $3$
$4$ $2$ $1$ $1$ $2$ $2$

若問「有多少頭乳牛在第 1 題回答 2、第 2 題回答 1?」,答案為 1,只有 4 號乳牛。若問「有多少頭乳牛在第 1 題和第 3 題都回答 1?」,答案為 2,是 1 號和 3 號乳牛。

輸入格式

  • 第 1 行:三個空格分隔的整數 $N$、$NQ$ 和 $P$。
  • 第 $2\ldots N+1$ 行:第 $i+1$ 行包含 $NQ$ 個空格分隔的整數,是乳牛 $i$ 的答案 $R_{1}\ldots R_{NQ}$。
  • 第 $N+2\ldots N+1+P$ 行:第 $j+N+1$ 行包含兩個空格分隔的整數 $Qj$ 和 $Aj$。

輸出格式

  • 第 1 行:一個整數,表示滿足 Bessie 所有條件的乳牛數量。

範例

輸入格式 1

4 5 2
1 1 1 1 1
1 2 3 4 5
1 2 1 2 3
2 1 1 2 2
1 1
3 1

輸出格式 1

2

題目作者:Rob Kolstad,2010

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.