QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#368811 | #5099. 朝圣道 | zyc070419 | 44 | 3921ms | 82684kb | C++14 | 4.0kb | 2024-03-27 16:45:10 | 2024-03-27 16:45:26 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
//#include "pilgrimage.h"
using namespace std;
int mod, inv;
map<ll, int> mp;
inline int add(int x, int y) {x += y; return x >= mod ? x - mod : x;}
inline int del(int x, int y) {x -= y; return x < 0 ? x + mod : x;}
inline void Add(int &x, int y) {x = add(x, y);}
inline void Del(int &x, int y) {x = del(x, y);}
inline int qpow(int x, ll y) {
int res = 1;
while (y) {
if (y & 1ll) res = 1ll * res * x % mod;
x = 1ll * x * x % mod;
y >>= 1;
}
return res;
}
namespace my_ex_Lucas {
struct node {
int p, c, pw, m, im, phi;
vector<int> pre, qpw, iv;
};
int p, cnt;
node a[20];
void ex_gcd(int A, int B, int &x, int &y) {
if (!B) return x = 1, y = 0, void();
int xx, yy;
ex_gcd(B, A % B, xx, yy);
x = yy; y = xx - A / B * yy;
}
inline int get_inv(int v, int mod) {
int x, y;
ex_gcd(v, mod, x, y);
x = (x % mod + mod) % mod;
assert(1ll * v * x % mod == 1);
return x;
}
void init(int P) {
int x = p = P; cnt = 0;
for (int i = 2; i * i <= x; ++i) {
if (x % i) continue;
int num = 0, now = 1;
while (x % i == 0) num++, now *= i, x /= i;
cnt++;
a[cnt].p = i; a[cnt].c = num; a[cnt].pw = now; a[cnt].m = p / now; a[cnt].im = get_inv(a[cnt].m % a[cnt].pw, a[cnt].pw);
a[cnt].phi = now - now / i;
a[cnt].pre.resize(now);
a[cnt].pre[0] = 1;
for (int j = 1; j < now; ++j) a[cnt].pre[j] = 1ll * a[cnt].pre[j - 1] * (j % i == 0 ? 1 : j) % now;
a[cnt].qpw.resize(a[cnt].phi * 2);
a[cnt].qpw[0] = 1;
for (int j = 1; j < a[cnt].phi * 2; ++j) a[cnt].qpw[j] = 1ll * a[cnt].qpw[j - 1] * a[cnt].pre[now - 1] % now;
a[cnt].iv.resize(now);
for (int j = 1; j < now; ++j)
if (j % i) a[cnt].iv[j] = get_inv(j, now);
}
if (x > 1) {
cnt++;
a[cnt].p = x; a[cnt].c = 1; a[cnt].pw = x; a[cnt].m = p / x; a[cnt].im = get_inv(a[cnt].m % a[cnt].pw, a[cnt].pw);
a[cnt].phi = x - 1;
a[cnt].pre.resize(x);
a[cnt].pre[0] = 1;
for (int j = 1; j < x; ++j) a[cnt].pre[j] = 1ll * a[cnt].pre[j - 1] * j % x;
a[cnt].qpw.resize(a[cnt].phi * 2);
a[cnt].qpw[0] = 1;
for (int j = 1; j < a[cnt].phi * 2; ++j) a[cnt].qpw[j] = 1ll * a[cnt].qpw[j - 1] * a[cnt].pre[x - 1] % x;
a[cnt].iv.resize(x);
for (int j = 1; j < x; ++j) a[cnt].iv[j] = get_inv(j, x);
}
}
int calc(ll n, int id) {
ll mem = n / a[id].pw;
if (mem >= a[id].phi) mem = mem % a[id].phi + a[id].phi;
return 1ll * a[id].qpw[mem] * a[id].pre[n % a[id].pw] % a[id].pw;
}
int work(ll n, ll m, int id) {
int o = 0, res = 1, ire = 1;
res = calc(n, id);
ire = 1ll * calc(m, id) * calc(n - m, id) % a[id].pw;
for (ll now = a[id].p; now <= n; now *= (ll)a[id].p) {
o += n / now - m / now - (n - m) / now;
res = 1ll * res * calc(n / now, id) % a[id].pw;
ire = 1ll * ire * calc(m / now, id) % a[id].pw * calc((n - m) / now, id) % a[id].pw;
}
res = 1ll * res * a[id].iv[ire] % a[id].pw;
if (o >= a[id].c) return 0;
while (o--) res = 1ll * res * a[id].p % a[id].pw;
return res;
}
int ex_Lucas(ll n, ll m) {
if (n < 0 || m < 0 || n < m) return 0;
int res = 0;
for (int i = 1; i <= cnt; ++i) {
int tmp = work(n, m, i);
res = (res + 1ll * tmp * a[i].m % p * a[i].im % p) % p;
}
return res;
}
}
using my_ex_Lucas :: ex_Lucas;
using my_ex_Lucas :: get_inv;
void init(int o, int p) {
mod = p;
inv = (mod + 1) / 2;
my_ex_Lucas :: init(p);
}
int ask(ll n) {
if (mp.count(n)) return mp[n];
if (n == 1) return mp[n] = inv;
bool pd1 = (__gcd((int)((n - 1) % mod), mod) != 1);
bool pd2 = (__gcd((int)((n - 2) % mod), mod) != 1);
if (pd1 && pd2) return 0;
else if (!pd1)
mp[n] = 8ll * (2ll * n % mod - 3) % mod * (2ll * n % mod - 1) % mod * ex_Lucas(2ll * n - 4, n - 2) % mod * get_inv((n - 1) % mod, mod) % mod * qpow(inv, 2ll * n + 1) % mod;
else
mp[n] = 8ll * (2ll * n % mod - 3) % mod * (2ll * n % mod - 1) % mod * ex_Lucas(2ll * n - 4, n - 3) % mod * get_inv((n - 2) % mod, mod) % mod * qpow(inv, 2ll * n + 1) % mod;
return mp[n];
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 4
Accepted
time: 89ms
memory: 15852kb
input:
1 910276 554767 6 10 7 4 10 12 9 3 3 5 7 10 5 6 1 6 3 9 6 8 12 11 8 2 12 5 9 3 8 2 12 11 2 3 4 9 2 5 5 11 6 4 8 11 3 9 2 2 8 9 2 8 9 6 2 9 2 10 10 7 5 6 4 4 11 12 8 8 2 2 4 3 3 5 6 6 8 11 6 9 9 3 4 1 2 2 6 9 9 2 3 2 12 6 1 7 2 4 12 11 4 7 6 3 9 4 6 5 3 3 12 6 2 1 1 7 2 6 5 9 11 6 3 4 11 1 2 4 5 4 10...
output:
5419 364275 514407 329394 364275 229662 53120 520095 520095 509260 514407 364275 509260 5419 277384 5419 520095 53120 5419 115262 229662 243797 115262 416076 229662 509260 53120 520095 115262 416076 229662 243797 416076 520095 329394 53120 416076 509260 509260 243797 5419 329394 115262 243797 520095...
result:
ok 910276 numbers
Test #2:
score: -4
Wrong Answer
time: 31ms
memory: 7648kb
input:
1 972231 293475 7 1 9 6 5 1 11 5 5 12 2 2 7 3 4 10 10 3 2 10 7 1 10 9 1 3 5 6 7 2 7 4 1 10 1 9 3 10 10 2 6 11 4 10 12 8 5 2 12 4 9 12 7 2 12 4 3 1 2 9 12 1 4 5 6 12 6 5 9 2 5 12 3 4 6 12 12 2 1 6 4 12 10 5 12 7 9 8 3 8 10 5 3 6 12 7 7 10 7 10 8 7 7 2 2 4 8 6 10 8 11 6 11 10 3 9 5 2 5 1 10 2 11 4 4 3...
output:
0 146738 29445 289464 209790 146738 0 209790 209790 158067 220107 220107 0 201765 284305 145210 145210 201765 220107 145210 0 146738 145210 29445 146738 201765 209790 289464 0 220107 0 284305 146738 145210 146738 29445 201765 145210 145210 220107 289464 0 284305 145210 158067 0 209790 220107 158067 ...
result:
wrong answer 1st numbers differ - expected: '117936', found: '0'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 12
Accepted
Test #5:
score: 12
Accepted
time: 33ms
memory: 10436kb
input:
3 1 334547 8234
output:
179079
result:
ok 1 number(s): "179079"
Subtask #4:
score: 18
Accepted
Dependency #3:
100%
Accepted
Test #6:
score: 18
Accepted
time: 714ms
memory: 33848kb
input:
4 1000000 581873 49881 62491 206405 26106 129239 174098 141494 61402 149825 241992 8109 243567 71918 203927 278575 263516 143582 32237 195508 269119 9111 105700 80919 229859 150334 171917 78447 62500 190063 138903 6395 222902 118653 136505 242467 64984 170330 287622 27089 35823 107672 273459 188857 ...
output:
225562 278095 494263 533616 449513 172629 433105 169217 156602 470240 127840 224903 148625 143635 385698 428034 270424 224704 326598 317786 205590 556103 563899 492571 87003 417735 350849 476300 65308 462020 373541 56205 35476 425631 345156 395965 377993 402141 119653 299737 4555 400632 420936 58015...
result:
ok 1000000 numbers
Subtask #5:
score: 14
Accepted
Dependency #4:
100%
Accepted
Test #7:
score: 14
Accepted
time: 2000ms
memory: 82684kb
input:
5 1000000 840643 596357868225427095 792903040511847841 549819683428503148 982786835970534376 855138540813992974 101968907510306081 885121351101383723 127972727417081251 728407510651610501 998897446686193527 889398142082696651 17276066104970301 87773104284997915 716559595019194816 538865162230963483 ...
output:
0 149057 0 0 0 0 13853 0 0 0 618602 0 0 0 0 0 243219 264897 0 0 0 0 0 0 0 0 0 0 0 0 311655 0 0 0 670015 171419 0 0 0 0 0 0 0 0 763198 247491 0 0 0 0 0 0 0 0 0 0 0 513609 0 0 0 0 0 0 0 0 0 0 0 0 0 0 37092 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 720992 0 0 456272 0 0 0 0 0 210850 0 0 0 0 0 383431 0 0 ...
result:
ok 1000000 numbers
Subtask #6:
score: 0
Wrong Answer
Test #8:
score: 12
Accepted
time: 2722ms
memory: 68156kb
input:
6 958477 522361 280121915553826833 734266539148641647 72849162479700582 274266741463686096 60278972064195458 828423669427600612 571432949203039978 518511460268700898 486268614705621285 19216283231217074 611458416727512530 175147354285288662 799769622289998997 400123443628688299 145546980862133838 40...
output:
0 0 0 0 0 0 0 0 0 0 0 193620 0 0 0 138180 0 0 0 0 0 264460 0 0 0 0 0 458514 0 0 0 0 0 0 0 0 0 144011 0 516922 0 0 0 471569 0 189623 0 0 0 0 0 0 0 0 0 0 324506 466417 0 0 0 0 0 0 0 0 0 0 485170 0 0 512806 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 189161 0 0 0 191079 0 0 0 0 0 0 0 0 0 0 0 421120 0 0 0 0 0 0 0 0...
result:
ok 958477 numbers
Test #9:
score: -12
Wrong Answer
time: 3921ms
memory: 64528kb
input:
6 955832 455871 68195868797525446 952386767279138889 842103266292995505 840751519399679445 381478477655923549 435500089497041045 90996577129314500 835530589245892594 335186020054452993 368796095079538576 343648428400752269 149581187007562672 361932544298643774 852760910071550430 334542588842244106 1...
output:
0 0 0 0 0 0 0 0 0 0 0 357474 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 388596 0 0 0 0 0 0 0 0 0 0 221520 0 0 0 259467 144495 0 0 0 0 0 0 0 0 0 280605 0 0 0 0 0 0 0 0 0 0 0 0 443508 0 0 0 110058 0 0 0 40755 0 0 0 0 0 0 128739 0 0 0 0 343980 0 0 269217 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 232...
result:
wrong answer 443rd numbers differ - expected: '79092', found: '0'
Subtask #7:
score: 0
Time Limit Exceeded
Dependency #3:
100%
Accepted
Test #13:
score: 8
Accepted
time: 1ms
memory: 5640kb
input:
7 1 731039 314313205082038759
output:
0
result:
ok 1 number(s): "0"
Test #14:
score: 0
Accepted
time: 0ms
memory: 5720kb
input:
7 1 587945 675184352277027016
output:
0
result:
ok 1 number(s): "0"
Test #15:
score: 0
Accepted
time: 10ms
memory: 6680kb
input:
7 1 732151 522404464427087971
output:
0
result:
ok 1 number(s): "0"
Test #16:
score: 0
Accepted
time: 1ms
memory: 5656kb
input:
7 1 952025 865782493150981281
output:
0
result:
ok 1 number(s): "0"
Test #17:
score: 0
Accepted
time: 2ms
memory: 5808kb
input:
7 1 151005 80048698775676684
output:
0
result:
ok 1 number(s): "0"
Test #18:
score: 0
Accepted
time: 1ms
memory: 5772kb
input:
7 1 819153 214538328031265195
output:
0
result:
ok 1 number(s): "0"
Test #19:
score: 0
Accepted
time: 1ms
memory: 5716kb
input:
7 1 84501 605460166753167761
output:
0
result:
ok 1 number(s): "0"
Test #20:
score: 0
Accepted
time: 1ms
memory: 5776kb
input:
7 1 579977 434091105518396762
output:
0
result:
ok 1 number(s): "0"
Test #21:
score: 0
Accepted
time: 1ms
memory: 5652kb
input:
7 1 161075 649828935660369724
output:
0
result:
ok 1 number(s): "0"
Test #22:
score: 0
Accepted
time: 1ms
memory: 5656kb
input:
7 1 629595 216539117331686464
output:
0
result:
ok 1 number(s): "0"
Test #23:
score: 0
Accepted
time: 1ms
memory: 5720kb
input:
7 1 317005 831315176686118434
output:
0
result:
ok 1 number(s): "0"
Test #24:
score: 0
Accepted
time: 0ms
memory: 5688kb
input:
7 1 204399 934354294367869212
output:
0
result:
ok 1 number(s): "0"
Test #25:
score: 0
Accepted
time: 1ms
memory: 5708kb
input:
7 1 98233 515248809013032256
output:
0
result:
ok 1 number(s): "0"
Test #26:
score: -8
Time Limit Exceeded
input:
7 1 738315 930635383520033839
output:
Unauthorized output
result:
Subtask #8:
score: 0
Wrong Answer
Test #33:
score: 0
Wrong Answer
time: 13ms
memory: 6384kb
input:
8 9963 251 831797004675585320 494759973681332858 701341496127272302 252910460485222469 250965009655458584 366193481309061299 633134388675839346 791999098066205672 196620805863610860 363773642045280947 466508590762410710 407790578717064135 181590911404670570 570642047249889864 70138464625729452 23634...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 204 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 63 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
wrong output format Expected integer, but "
Subtask #9:
score: 0
Skipped
Dependency #1:
0%