2019 ICPC 邀请赛(南昌) B-Polynomial

已知$f_0..f_n$,求$\sum_l^r f(i)$

傻逼卡常题,模版题。预处理下阶乘和连乘的东西就可少个$log$。

代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define mk make_pair
const int N = 2e6 + 10;
const int mod = 9999991;

int read()
{
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9')
{
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = (x << 1) + (x << 3) + c - '0', c = getchar();
return x * f;
}
int inc(int x, int y)
{
if (y < 0)
y += mod;
if (x + y >= mod)
x -= mod;
return x + y;
}
int qpow(int a, int x, int mo)
{
int res = 1;
while (x)
{
if (x & 1)
res = 1ll * res * a % mo;
x >>= 1;
a = 1ll * a * a % mo;
}
return res;
}

int fac[N];
int pre[N], suf[N];
int get(int *y, int x, int len)
{
if (x < 0)
return 0;
if (x <= len)
return y[x];
int ans = 0;
pre[0] = suf[len] = 1;
for (int i = 1; i <= len; ++i)
pre[i] = 1ll * pre[i - 1] * (x - i + 1) % mod;
for (int i = len; i >= 1; --i)
suf[i - 1] = 1ll * suf[i] * (x - i) % mod;
for (int i = 0; i <= len; i++)
{
int s1 = 1ll * pre[i] * suf[i] % mod;
int s2 = 1ll * fac[i] * fac[len - i] % mod;
if ((len - i) & 1)
s2 = (mod - s2) % mod;
//cout << s1 << " " << s2 << endl;
ans = inc(ans, 1ll * y[i] * s1 % mod * s2 % mod);
}
return ans;
}
int y[N];
int f[N];
int n, m;
int main()
{
int T = read();
fac[0] = 1;
for (int i = 1; i <= 3000; i++)
fac[i] = 1ll * fac[i - 1] * i % mod;
for (int i = 1; i <= 3000; i++)
fac[i] = qpow(fac[i], mod - 2, mod);
while (T--)
{
n = read(), m = read();

for (int i = 0; i <= n; i++)
f[i] = read();
f[n + 1] = get(f, n + 1, n);
//cout << f[n + 1] << endl;
y[0] = f[0];
for (int i = 1; i <= n + 1; i++)
y[i] = inc(y[i - 1], f[i]);

while (m--)
{
int L = read(), R = read();
printf("%d\n", inc(get(y, R, n + 1), -get(y, L - 1, n + 1)));
}
}
}