当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

7203:Shinobu loves trip

题目描述
As a cold-blooded, hot-blooded, and iron-blooded vampire, Shinobu loves traveling around.

There are $P$ countries in total, numbered $0,1,\dots ,P-1$.(It is guaranteed that $P$ is a prime number)

It is known that when Shinobu is in the country numbered $i$, the next country she visits must be the country numbered $(i\cdot a) \mod P$ ($a$ is a constant parameter), and it takes Shinobu $1$ day to go from one country to another.

In order to travel smoothly, Shinobu has customized $n$ travel plans, and the $i$-th travel plan is represented by the starting country $s_i$ and the travel days $d_i$.

For example, if $P = 233,\ a = 2$, a plan's starting country is $1$ and travel days is $2$, then Shinobu will visit the city $\{ 1,2,4 \}$ according to this plan.

Playf knows these travel plans and the value of parameter $a$, now he wants to ask you $q$ questions. The $i$-th question asks how many travel plans will make shinobu visit the country $x_i$.
输入解释
The first line of the input contains one integer $T$ $($$1\leq T\leq 5$ $)$ --- the number of test cases. Then $T$ test cases follow.

For each testcase, the first line contains four integers $P,\ a,\ n,\ q(2\le a< P \le 1000000007, 1\le n \le 1000, 1\le q \le 1000 )$ --- the number of countries, the value of $a$, the number of Shinobu's travel plans and the number of playf's questions.

Each of the next $n$ lines contains two integers $s_i,\ d_i(0\le s_i< P, 1\le d_i \le 200000 )$ --- the starting country and the travel days.

Each of the next $q$ lines contains one integer $x_i(0\le x_i< P)$ --- playf's questions.

It is guaranteed that $P$ is a prime number.
输出解释
For each testcase, print $q$ lines, the $i$-th line contains one integer --- the answer to the $i$-th question.
输入样例
2
3 2 1 1
1 1
2
5 4 3 2
1 4
4 3
2 100000
4
2
输出样例
1
2
1

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-7203

最后修改于 2022-09-15T06:17:20+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
6000/3000MS(Java/Others) 524288/262144K(Java/Others)