QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#101324 | #5031. 核 | zhoukangyang | 40 | 198ms | 3512kb | C++17 | 1.6kb | 2023-04-29 09:49:27 | 2023-04-29 09:49:30 |
Judging History
answer
#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define vi vector <int>
#define sz(a) ((int) (a).size())
#define me(f, x) memset(f, x, sizeof(f))
#define uint unsigned int
#define ull unsigned long long
#define bs bitset < N >
using namespace std;
const int N = 5e5 + 7;
int n, q, mod;
int pw[N], fac[N], ifac[N];
int qpow(int x, int y = mod - 2) {
int res = 1;
for(; y; x = (ll) x * x % mod, y >>= 1) if(y & 1) res = (ll) res * x % mod;
return res;
}
void q_init(int x) {
pw[0] = 1;
L(i, 1, x) pw[i] = (ll) pw[i - 1] * q % mod;
L(i, 1, x) fac[i] = (fac[i - 1] + pw[i - 1]) % mod;
fac[0] = ifac[0] = 1;
L(i, 1, x)
ifac[i] = (ll) qpow (fac[i]) * ifac[i - 1] % mod,
fac[i] = (ll) fac[i - 1] * fac[i] % mod;
}
int q_C(int x, int y) {
return x < y || y < 0 ? 0 : (ll) fac[x] * ifac[y] % mod * ifac[x - y] % mod;
}
int f[N];
int nig[N];
int main() {
ios :: sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> q >> mod;
q_init(n + 1);
L(i, 0, n) {
int prd = 1;
L(j, 0, i - 1)
prd = (ll) prd * (pw[i] + mod - pw[j]) % mod;
f[i] = (ll) prd * qpow(q, (ll)i * (n - i) % (mod - 1)) % mod;
}
L(i, 0, n)
L(j, 0, i - 1)
(f[i] += mod - (ll) f[j] * q_C(i, j) % mod) %= mod;
L(i, 0, n) {
f[i] = (ll) f[i] * q_C(n, i) % mod;
}
int pw = 1;
L(i, 1, n) {
pw = (ll) pw * q % (mod - 1);
}
int s = 1, ns = 0;
R(i, n, 0) {
(ns += (ll) f[i] * qpow(3, s) % mod) %= mod;
s = (ll) s * pw % (mod - 1);
}
cout << ns << '\n';
return 0;
}
詳細信息
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 1ms
memory: 3384kb
input:
1 2 540053233
output:
9
result:
ok 1 number(s): "9"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3236kb
input:
2 2 156542707
output:
43046970
result:
ok 1 number(s): "43046970"
Test #3:
score: 0
Accepted
time: 2ms
memory: 3296kb
input:
1 2 186225229
output:
9
result:
ok 1 number(s): "9"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3332kb
input:
3 3 109884329
output:
100602209
result:
ok 1 number(s): "100602209"
Test #5:
score: 0
Accepted
time: 2ms
memory: 3312kb
input:
1 2 144802297
output:
9
result:
ok 1 number(s): "9"
Subtask #2:
score: 20
Accepted
Dependency #1:
100%
Accepted
Test #6:
score: 20
Accepted
time: 0ms
memory: 3376kb
input:
20 21992843 328859143
output:
110137213
result:
ok 1 number(s): "110137213"
Test #7:
score: 0
Accepted
time: 2ms
memory: 3320kb
input:
22 332524739 654888401
output:
410922781
result:
ok 1 number(s): "410922781"
Test #8:
score: 0
Accepted
time: 1ms
memory: 3320kb
input:
26 302215049 566649113
output:
221720840
result:
ok 1 number(s): "221720840"
Test #9:
score: 0
Accepted
time: 3ms
memory: 3492kb
input:
15 111009527 722130737
output:
648834664
result:
ok 1 number(s): "648834664"
Test #10:
score: 0
Accepted
time: 2ms
memory: 3328kb
input:
82 110032063 394529383
output:
111730592
result:
ok 1 number(s): "111730592"
Test #11:
score: 0
Accepted
time: 2ms
memory: 3384kb
input:
9 11172911 259650437
output:
68381774
result:
ok 1 number(s): "68381774"
Test #12:
score: 0
Accepted
time: 2ms
memory: 3324kb
input:
86 12016027 354886243
output:
263687778
result:
ok 1 number(s): "263687778"
Test #13:
score: 0
Accepted
time: 1ms
memory: 3376kb
input:
91 273689959 454097881
output:
114436127
result:
ok 1 number(s): "114436127"
Test #14:
score: 0
Accepted
time: 2ms
memory: 3336kb
input:
73 148878967 694206977
output:
176215101
result:
ok 1 number(s): "176215101"
Test #15:
score: 0
Accepted
time: 0ms
memory: 3484kb
input:
45 205982233 227598247
output:
156769598
result:
ok 1 number(s): "156769598"
Subtask #3:
score: 10
Accepted
Dependency #2:
100%
Accepted
Test #16:
score: 10
Accepted
time: 174ms
memory: 3428kb
input:
2778 122825869 147297463
output:
43419574
result:
ok 1 number(s): "43419574"
Test #17:
score: 0
Accepted
time: 4ms
memory: 3296kb
input:
289 7729669 589652893
output:
552952137
result:
ok 1 number(s): "552952137"
Test #18:
score: 0
Accepted
time: 119ms
memory: 3512kb
input:
2281 35651417 203950963
output:
21659018
result:
ok 1 number(s): "21659018"
Test #19:
score: 0
Accepted
time: 63ms
memory: 3348kb
input:
1684 258745639 373223677
output:
355596229
result:
ok 1 number(s): "355596229"
Test #20:
score: 0
Accepted
time: 102ms
memory: 3304kb
input:
2107 86850989 455823859
output:
245960059
result:
ok 1 number(s): "245960059"
Test #21:
score: 0
Accepted
time: 42ms
memory: 3340kb
input:
1323 43290799 791120419
output:
509649562
result:
ok 1 number(s): "509649562"
Test #22:
score: 0
Accepted
time: 128ms
memory: 3468kb
input:
2401 34064903 185314627
output:
70571452
result:
ok 1 number(s): "70571452"
Test #23:
score: 0
Accepted
time: 29ms
memory: 3496kb
input:
1073 82288187 564447959
output:
168200843
result:
ok 1 number(s): "168200843"
Test #24:
score: 0
Accepted
time: 85ms
memory: 3348kb
input:
1926 29995039 129122281
output:
60921463
result:
ok 1 number(s): "60921463"
Test #25:
score: 0
Accepted
time: 198ms
memory: 3360kb
input:
3000 66915659 765705179
output:
222619979
result:
ok 1 number(s): "222619979"
Subtask #4:
score: 0
Runtime Error
Test #26:
score: 0
Runtime Error
input:
998818 198334853 998244353
output:
result:
Subtask #5:
score: 0
Runtime Error
Test #36:
score: 0
Runtime Error
input:
9909956 720431399 720431401
output:
result:
Subtask #6:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
0%