Codeforces Round 1058 (Div. 1)
E
Super-Short-Polynomial-San
Codeforces
3500
原题
← D2F →
翻译中…

This problem might be well-known in some countries, but how do other countries learn about such problems if nobody poses them?— XXI Open Cup, Grand Prix of Tokyo

翻译中…

You are given three integers $a,b,c$.

翻译中…

Let $F(n)$ be the polynomial of degree $2n$ defined as follows.

翻译中…

$$F(n)=\left ({a x^2+b x+c}\right) ^n$$

翻译中…

You are asked to solve $q$ queries of the following kind.

翻译中…
  • $n\;k$: Please find the value of the sum $\displaystyle \sum_{i=0}^{k}{\left [ {x^i} \right] F(n)}$ modulo $10^9+7$$^{\text{∗}}$.
翻译中…

However, it might be too easy for you if this problem ends here. So here is a twist$^{\text{†}}$: You are asked to solve the queries online.

翻译中…

$^{\text{∗}}$Here, $[x^a]F(n)$ denotes the coefficient of $x^a$ of the polynomial $F(n)$.$^{\text{†}}$I hope it isn't too hard for you after the twist. Even a toddler knows one way to solve it. You just have to optimize that method by a factor of $8\,000\,000$.

翻译中…

Input

翻译中…

The first line contains three integers $a$, $b$, $c$ ($1 \le a,b,c \le 10^9+6$).

翻译中…

The second line contains the number of queries $q$ ($1 \le q \le 3 \cdot 10^5$).

翻译中…

Each of the $q$ following lines contains two integers $n_i'$ and $k_i'$ denoting the query in encrypted format.

翻译中…

You must decrypt the queries as follows.

翻译中…
  • Let the answer to the $i$-th query modulo $10^9+7$ be $ans_i$. Here, $ans_0$ is defined to be $0$.
  • Then, the values of $n$ and $k$ for the $i$-th query are $n_i = n_i' \oplus ans_{i-1}$ and $k_i = k_i' \oplus ans_{i-1}$ ($0 \le n_i \le 3\cdot 10^5$, $0 \le k_i \le 2n_i$).
翻译中…

Do note that both the sum of $n_i$ and the sum of $k_i$ over all queries are not bounded.

翻译中…

Output

翻译中…

For each query, print the answer modulo $10^9+7$ on a new line.

翻译中…

Note

翻译中…

The decrypted example input is as follows.

翻译中…

3 2 1
11
0 0
1 0
1 1
1 2
2 0
2 1
2 2
2 3
2 4
31415 9265
200000 69420

翻译中…

Here, the polynomial $F(n)$ corresponds to A084608 from OEIS. Don't worry about the link; there's nothing so useful there. Trust me.

翻译中…

样例

Input #1
3 2 1
11
0 0
0 1
0 0
2 1
4 6
3 0
7 7
13 12
25 31
31379 9237
396176013 396306657
Output #1
1
1
3
6
1
5
15
27
36
396240845
819003547
InputCopy OutputCopy
题目信息
题号
2159E
时间限制
7 s
内存限制
1024 MB
标签
数学
折半搜索

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。