CF2159E.Super-Short-Polynomial-San
NOI/NOI+/CTSC
通过率:0%
时间限制:7.00s
内存限制:1024MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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(ax2+bx+cright)n
You are asked to solve q queries of the following kind.
- nk: Please find the value of the sum i=0∑k[xi]F(n) modulo 109+7∗.
However, it might be too easy for you if this problem ends here. So here is a twist†: You are asked to solve the queries online.
∗Here, [xa]F(n) denotes the coefficient of xa of the polynomial F(n).
†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 8000000.
这个问题在某些国家可能早已广为人知,但如果没人将其提出,其他国家又怎能了解到这类问题呢?
给定三个整数 a,b,c。
定义次数为 2n 的多项式 F(n) 如下:
F(n)=(ax2+bx+c)n
你需要回答 q 个如下形式的查询:
- nk:请计算 i=0∑k[xi]F(n) 对 109+7 取模的结果∗。
然而,如果本题仅止步于此,对你而言或许过于简单。因此,这里有一个转折†:你需要在线处理这些查询。
∗此处,[xa]F(n) 表示多项式 F(n) 中 xa 项的系数。
†希望这个转折不会让你觉得太难。哪怕一个学步的幼儿都知道一种解法。你只需将该方法优化 8000000 倍即可。
输入格式
The first line contains three integers a, b, c (1≤a,b,c≤109+6).
The second line contains the number of queries q (1≤q≤3⋅105).
Each of the q following lines contains two integers ni′ and ki′ denoting the query in encrypted format.
You must decrypt the queries as follows.
- Let the answer to the i-th query modulo 109+7 be ansi. Here, ans0 is defined to be 0.
- Then, the values of n and k for the i-th query are ni=ni′⊕ansi−1 and ki=ki′⊕ansi−1 (0≤ni≤3⋅105, 0≤ki≤2ni).
Do note that both the sum of ni and the sum of ki over all queries are not bounded.
第一行包含三个整数 a、b、c(1≤a,b,c≤109+6)。
第二行包含查询次数 q(1≤q≤3⋅105)。
接下来的 q 行中,每行包含两个整数 ni′ 和 ki′,表示以加密形式给出的第 i 个查询。
你需要按如下方式对查询进行解密:
- 设第 i 个查询的答案对 109+7 取模的结果为 ansi;此处定义 ans0=0。
- 则第 i 个查询对应的 n 和 k 的值为 ni=ni′⊕ansi−1 和 ki=ki′⊕ansi−1(满足 0≤ni≤3⋅105,0≤ki≤2ni)。
请注意:所有查询的 ni 之和以及所有查询的 ki 之和均无上界限制。
输出格式
For each query, print the answer modulo 109+7 on a new line.
对于每个查询,在新行中输出答案对 109+7 取模的结果。
输入输出样例
输入#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
输出#1
1 1 3 6 1 5 15 27 36 396240845 819003547
说明/提示
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.
解密后的示例输入如下:
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
此处,多项式 F(n) 对应于 OEIS 中的序列 A084608。无需关注该链接;其中并无特别有用的信息。请相信我。
输入解题思路,AI测评打分。不知道怎么写?