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,ca,b,c.

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

F(n)=left(ax2+bx+cright)nF(n)=\\left ({a x^2+b x+c}\\right) ^n

You are asked to solve qq queries of the following kind.

  • n  kn\;k: Please find the value of the sum ∑i=0k[xi]F(n)\displaystyle \sum_{i=0}^{k}{\left [ {x^i} \right] F(n)} modulo 109+710^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, [xa]F(n)[x^a]F(n) denotes the coefficient of xax^a of the polynomial F(n)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 0008\,000\,000.

这个问题在某些国家可能早已广为人知,但如果没人将其提出,其他国家又怎能了解到这类问题呢?

— 第21届开放杯东京站大奖赛

给定三个整数 a,b,ca,b,c。

定义次数为 2n2n 的多项式 F(n)F(n) 如下:

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

你需要回答 qq 个如下形式的查询:

  • n  kn\;k:请计算 ∑i=0k[xi]F(n)\displaystyle \sum_{i=0}^{k}{\left [ {x^i} \right] F(n)} 对 109+710^9+7 取模的结果∗^{\text{∗}}。

然而,如果本题仅止步于此,对你而言或许过于简单。因此,这里有一个转折†^{\text{†}}:你需要在线处理这些查询。

∗^{\text{∗}}此处,[xa]F(n)[x^a]F(n) 表示多项式 F(n)F(n) 中 xax^a 项的系数。

†^{\text{†}}希望这个转折不会让你觉得太难。哪怕一个学步的幼儿都知道一种解法。你只需将该方法优化 8 000 0008\,000\,000 倍即可。

输入格式

The first line contains three integers aa, bb, cc (1≤a,b,c≤109+61 \le a,b,c \le 10^9+6).

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

Each of the qq following lines contains two integers ni′n_i' and ki′k_i' denoting the query in encrypted format.

You must decrypt the queries as follows.

  • Let the answer to the ii-th query modulo 109+710^9+7 be ansians_i. Here, ans0ans_0 is defined to be 00.
  • Then, the values of nn and kk for the ii-th query are ni=ni′⊕ansi−1n_i = n_i' \oplus ans_{i-1} and ki=ki′⊕ansi−1k_i = k_i' \oplus ans_{i-1} (0≤ni≤3⋅1050 \le n_i \le 3\cdot 10^5, 0≤ki≤2ni0 \le k_i \le 2n_i).

Do note that both the sum of nin_i and the sum of kik_i over all queries are not bounded.

第一行包含三个整数 aa、bb、cc(1≤a,b,c≤109+61 \le a,b,c \le 10^9+6)。

第二行包含查询次数 qq(1≤q≤3⋅1051 \le q \le 3 \cdot 10^5)。

接下来的 qq 行中,每行包含两个整数 ni′n_i' 和 ki′k_i',表示以加密形式给出的第 ii 个查询。

你需要按如下方式对查询进行解密:

  • 设第 ii 个查询的答案对 109+710^9+7 取模的结果为 ansians_i;此处定义 ans0=0ans_0 = 0。
  • 则第 ii 个查询对应的 nn 和 kk 的值为 ni=ni′⊕ansi−1n_i = n_i' \oplus ans_{i-1} 和 ki=ki′⊕ansi−1k_i = k_i' \oplus ans_{i-1}(满足 0≤ni≤3⋅1050 \le n_i \le 3\cdot 10^5,0≤ki≤2ni0 \le k_i \le 2n_i)。

请注意:所有查询的 nin_i 之和以及所有查询的 kik_i 之和均无上界限制。

输出格式

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

对于每个查询,在新行中输出答案对 109+710^9+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)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)F(n) 对应于 OEIS 中的序列 A084608。无需关注该链接;其中并无特别有用的信息。请相信我。

输入解题思路,AI测评打分。不知道怎么写?

首页