QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#80456 | #5406. 随机游走 | Scintilla | 100 ✓ | 554ms | 289464kb | C++14 | 2.3kb | 2023-02-23 20:30:18 | 2023-02-23 20:30:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = s; i <= e; ++i)
#define drep(i, s, e) for (int i = s; i >= e; --i)
#define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout)
#define pv(a) cout << #a << " = " << a << endl
#define pa(a, l, r) cout << #a " : "; rep(_, l, r) cout << a[_] << ' '; cout << endl
const int P = 1e9 + 7;
const int N = 1e7 + 10;
int read() {
int x = 0, f = 1; char c = getchar();
for (; c < '0' || c > '9'; c = getchar()) if (c == '-') f = -1;
for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48;
return x * f;
}
int inc(int a, int b) { return (a += b) >= P ? a - P : a; }
int dec(int a, int b) { return (a -= b) < 0 ? a + P : a; }
int mul(int a, int b) { return 1ll * a * b % P; }
int qpow(int a, int b) { int res = 1; for (; b; b >>= 1, a = mul(a, a)) if (b & 1) res = mul(res, a); return res; }
int fac[N], inv[N], finv[N];
void init(int w) {
fac[0] = inv[1] = finv[0] = 1;
rep(i, 1, w) fac[i] = mul(fac[i - 1], i);
rep(i, 2, w) inv[i] = P - mul(P / i, inv[P % i]);
rep(i, 1, w) finv[i] = mul(finv[i - 1], inv[i]);
}
int C(int a, int b) {
if (a < b || b < 0) return 0;
return mul(fac[a], mul(finv[b], finv[a - b]));
}
int n, tot, p[N], a[N], pw[N], b[N], coef[N], ans;
bool tag[N];
void sieve(int w) {
pw[1] = 1;
rep(i, 2, w) {
if (!tag[i]) p[++ tot] = i, pw[i] = qpow(i, 2 * n);
for (int j = 1; j <= tot && i * p[j] <= w; ++ j) {
tag[i * p[j]] = true, pw[i * p[j]] = mul(pw[i], pw[p[j]]);
if (!(i % p[j])) break;
}
}
}
int solve(int l, int r) {
int res = 0;
rep(i, 0, r) {
res = inc(res, mul(a[i], dec(b[r - i], b[max(l - i - 1, 0)])));
}
return res;
}
int main() {
n = read(), init(2 * n + 1), sieve(2 * n + 1);
rep(i, 0, 2 * n) {
int t = mul(finv[i], finv[2 * n - i]);
i & 1 ? a[i] = P - t : a[i] = t;
}
rep(i, 1, 2 * n) b[i] = inc(b[i - 1], pw[i]);
rep(i, 1, 2 * n) {
int t = mul(mul(2 * n, i), inv[2 * n + 1]);
i <= n ? t = dec(n, t) : t = dec(t, n);
coef[i] = inc(coef[i], t), coef[i - 1] = dec(coef[i - 1], t);
}
for (int l = 1, r; l <= 2 * n; l = r + 1) {
for (r = l; r < 2 * n && coef[r + 1] == coef[l]; ++ r) ;
ans = inc(ans, mul(coef[l], solve(l, r)));
}
printf("%d\n", ans);
return 0;
}
詳細信息
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 2ms
memory: 3724kb
input:
1
output:
333333336
result:
ok 1 number(s): "333333336"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
2
output:
266666669
result:
ok 1 number(s): "266666669"
Test #3:
score: 0
Accepted
time: 2ms
memory: 3528kb
input:
3
output:
769047625
result:
ok 1 number(s): "769047625"
Subtask #2:
score: 10
Accepted
Test #4:
score: 10
Accepted
time: 2ms
memory: 3784kb
input:
4
output:
877865968
result:
ok 1 number(s): "877865968"
Test #5:
score: 0
Accepted
time: 2ms
memory: 3724kb
input:
5
output:
733342859
result:
ok 1 number(s): "733342859"
Test #6:
score: 0
Accepted
time: 2ms
memory: 3580kb
input:
6
output:
655899114
result:
ok 1 number(s): "655899114"
Test #7:
score: 0
Accepted
time: 2ms
memory: 3536kb
input:
7
output:
946326757
result:
ok 1 number(s): "946326757"
Test #8:
score: 0
Accepted
time: 1ms
memory: 3532kb
input:
8
output:
230714822
result:
ok 1 number(s): "230714822"
Test #9:
score: 0
Accepted
time: 2ms
memory: 3580kb
input:
9
output:
782967541
result:
ok 1 number(s): "782967541"
Test #10:
score: 0
Accepted
time: 2ms
memory: 3516kb
input:
10
output:
732371611
result:
ok 1 number(s): "732371611"
Subtask #3:
score: 10
Accepted
Test #11:
score: 10
Accepted
time: 3ms
memory: 3732kb
input:
15
output:
677123472
result:
ok 1 number(s): "677123472"
Test #12:
score: 0
Accepted
time: 2ms
memory: 3580kb
input:
13
output:
168974634
result:
ok 1 number(s): "168974634"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
26
output:
213343876
result:
ok 1 number(s): "213343876"
Test #14:
score: 0
Accepted
time: 2ms
memory: 3724kb
input:
29
output:
631124616
result:
ok 1 number(s): "631124616"
Subtask #4:
score: 15
Accepted
Test #15:
score: 15
Accepted
time: 2ms
memory: 3492kb
input:
37
output:
349256161
result:
ok 1 number(s): "349256161"
Test #16:
score: 0
Accepted
time: 1ms
memory: 3592kb
input:
104
output:
351095881
result:
ok 1 number(s): "351095881"
Test #17:
score: 0
Accepted
time: 2ms
memory: 3476kb
input:
194
output:
895504391
result:
ok 1 number(s): "895504391"
Test #18:
score: 0
Accepted
time: 2ms
memory: 3740kb
input:
197
output:
923555376
result:
ok 1 number(s): "923555376"
Test #19:
score: 0
Accepted
time: 0ms
memory: 3736kb
input:
198
output:
512220517
result:
ok 1 number(s): "512220517"
Subtask #5:
score: 15
Accepted
Test #20:
score: 15
Accepted
time: 2ms
memory: 3524kb
input:
562
output:
255062346
result:
ok 1 number(s): "255062346"
Test #21:
score: 0
Accepted
time: 2ms
memory: 3612kb
input:
1007
output:
735041605
result:
ok 1 number(s): "735041605"
Test #22:
score: 0
Accepted
time: 2ms
memory: 3796kb
input:
1788
output:
208261384
result:
ok 1 number(s): "208261384"
Test #23:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
1980
output:
875427987
result:
ok 1 number(s): "875427987"
Test #24:
score: 0
Accepted
time: 2ms
memory: 3592kb
input:
1983
output:
571776252
result:
ok 1 number(s): "571776252"
Test #25:
score: 0
Accepted
time: 0ms
memory: 3684kb
input:
1992
output:
12983695
result:
ok 1 number(s): "12983695"
Subtask #6:
score: 15
Accepted
Test #26:
score: 15
Accepted
time: 2ms
memory: 3776kb
input:
3946
output:
977435333
result:
ok 1 number(s): "977435333"
Test #27:
score: 0
Accepted
time: 10ms
memory: 7516kb
input:
65944
output:
312666196
result:
ok 1 number(s): "312666196"
Test #28:
score: 0
Accepted
time: 14ms
memory: 13092kb
input:
163815
output:
163767254
result:
ok 1 number(s): "163767254"
Test #29:
score: 0
Accepted
time: 8ms
memory: 15112kb
input:
198732
output:
911833524
result:
ok 1 number(s): "911833524"
Test #30:
score: 0
Accepted
time: 21ms
memory: 15112kb
input:
199287
output:
910277128
result:
ok 1 number(s): "910277128"
Test #31:
score: 0
Accepted
time: 20ms
memory: 15172kb
input:
199819
output:
561747634
result:
ok 1 number(s): "561747634"
Subtask #7:
score: 30
Accepted
Test #32:
score: 30
Accepted
time: 32ms
memory: 21560kb
input:
315618
output:
602805814
result:
ok 1 number(s): "602805814"
Test #33:
score: 0
Accepted
time: 115ms
memory: 68160kb
input:
1130465
output:
898203793
result:
ok 1 number(s): "898203793"
Test #34:
score: 0
Accepted
time: 488ms
memory: 255236kb
input:
4399723
output:
101317224
result:
ok 1 number(s): "101317224"
Test #35:
score: 0
Accepted
time: 507ms
memory: 278324kb
input:
4804460
output:
114947085
result:
ok 1 number(s): "114947085"
Test #36:
score: 0
Accepted
time: 523ms
memory: 289032kb
input:
4995726
output:
460040939
result:
ok 1 number(s): "460040939"
Test #37:
score: 0
Accepted
time: 543ms
memory: 289464kb
input:
4999919
output:
780785591
result:
ok 1 number(s): "780785591"
Test #38:
score: 0
Accepted
time: 554ms
memory: 289344kb
input:
4999999
output:
742624725
result:
ok 1 number(s): "742624725"