QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#67246 | #5099. 朝圣道 | Minion | 12 | 329ms | 116804kb | C++23 | 2.9kb | 2022-12-10 11:04:26 | 2022-12-10 11:04:28 |
Judging History
answer
#define ll long long
#define u64 unsigned long long
#define u128 __uint128_t
#define fo(i,x,y) for(int i = x;i <= y;++i)
namespace
{
struct fastmod
{
int m;u64 b;
void init(int p) {m = p,b = ((u128)(1) << 64) / m;}
u64 operator ()(u64 a)
{
u64 q = (u128)(a) * b >> 64;
u64 r = a - q * m;
return r < m ? r : r - m;
}
}FM;
int p,fac[2000010][7],pm[10],m,phi = 1,ans[7],mi[7][2000010],ifac[2000010];
int mi2[1000010];
int ksm(int x,ll y)
{
int res = 1;
for(;y;y >>= 1,x = FM(1ll * x * x)) if(y & 1) res = FM(1ll * res * x);
return res;
}
void inc(int &x,int y) {x = x + y >= p ? x + y - p : x + y;}
void M(int *f,int x)
{
fo(i,1,m) while(x % pm[i] == 0) x /= pm[i],++f[i];
f[0] = FM(1ll * f[0] * x);
}
int F[1000010];
int C(ll N,ll M)
{
if(N < M || M < 0 || N < 0) return 0;
if(N >= p || M >= p) return FM(1ll * C(N / p,M / p) * C(N % p,M % p));
int res[7];
fo(i,0,m) res[i] = FM(fac[N][i] * FM(1ll * ifac[M] * ifac[N - M]));
fo(i,1,m) res[i] -= fac[M][i] + fac[N - M][i];
int re = res[0];
fo(i,1,m) re = FM(1ll * re * mi[i][res[i]]);
return re;
}
int f(ll N,ll M)
{
if(M > N) M = N;
if(M < 0) return 0;
if(M == N) return mi2[FM(N)];
if(N == 0) return M == 1;
if(N <= p)
{
int res = 0;
fo(i,0,M - 1) inc(res,C(N,i));
return res;
}
return FM(1ll * mi2[2,FM(N)] * f(N / p,M / p) + 1ll * C(N / p,M / p) * f(FM(N),FM(M)));
}
int g(ll N,ll M)
{
if(M > N) M = N;
if(M == N) return FM(FM(N) * mi2[FM(N - 1)]);
if(N == 0) return 0;
if(N <= p)
{
int res = 0;
fo(i,0,M - 1) res = FM(res + 1ll * C(N,i) * i);
return res;
}
return FM(FM(mi2[FM(N - 1)] * FM(N)) * f(N / p,M / p) + 1ll * C(N / p,M / p) * g(FM(N),FM(M)));
}
}
void init(int o,int P)
{
FM.init(p = P);
for(int i = 2;i * i <= P;++i)
{
if(P % i == 0) P /= i,pm[++m] = i,phi *= i - 1;
while(P % i == 0) P /= i,phi *= i;
}
if(P > 1) pm[++m] = P,phi *= P - 1;
fac[0][0] = 1;
fo(i,1,2000000)
{
fo(j,0,m) fac[i][j] = fac[i - 1][j];
M(fac[i],i);
}
fo(i,1,2000000) ifac[i] = ksm(fac[i][0],phi - 1);
fo(i,1,m)
{
mi[i][0] = 1;
fo(j,1,2000000) mi[i][j] = FM(1ll * mi[i][j - 1] * pm[i]);
}
fo(i,1,1000000) F[i] = -1;
mi2[0] = 1;
fo(i,1,1000000) mi2[i] = FM(2 * mi2[i - 1]);
}
int ask(ll n)
{
if(m == 1)
{
int iv = ksm(p + 1 >> 1,n << 1);
int r1 = FM(FM(n) * (p + 1 - FM(1ll * iv * C(2 * n,n))));
int r2 = FM(2ll * g(2 * n,n) * iv);
return FM(r1 - r2 + p);
}
if(~F[n]) return F[n];
int res = 0;
fo(i,0,n - 1)
{
fo(j,0,m) ans[j] = fac[2 * n][j];
ans[0] = FM(FM(1ll * ifac[i] * ifac[2 * n - i]) * ans[0]);
fo(j,1,m) ans[j] -= fac[i][j] + fac[2 * n - i][j];
int re = ans[0];
fo(j,1,m) re = FM(1ll * re * mi[j][ans[j]]);
res = FM(res + 1ll * re * (n - i));
}
return F[n] = FM(1ll * res * ksm(p + 1 >> 1,2 * n - 1));
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 4
Accepted
time: 329ms
memory: 85504kb
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: 304ms
memory: 116804kb
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:
145915 0 112923 133842 278000 0 169445 278000 278000 245403 146738 146738 145915 210936 91712 233615 233615 210936 146738 233615 145915 0 233615 112923 0 210936 278000 133842 145915 146738 145915 91712 0 233615 0 112923 210936 233615 233615 146738 133842 169445 91712 233615 245403 92429 278000 14673...
result:
wrong answer 1st numbers differ - expected: '117936', found: '145915'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 12
Accepted
Test #5:
score: 12
Accepted
time: 173ms
memory: 81400kb
input:
3 1 334547 8234
output:
179079
result:
ok 1 number(s): "179079"
Subtask #4:
score: 0
Time Limit Exceeded
Dependency #3:
100%
Accepted
Test #6:
score: 0
Time Limit Exceeded
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:
Unauthorized output
result:
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Runtime Error
Test #8:
score: 0
Runtime Error
input:
6 958477 522361 280121915553826833 734266539148641647 72849162479700582 274266741463686096 60278972064195458 828423669427600612 571432949203039978 518511460268700898 486268614705621285 19216283231217074 611458416727512530 175147354285288662 799769622289998997 400123443628688299 145546980862133838 40...
output:
Unauthorized output
result:
Subtask #7:
score: 0
Runtime Error
Dependency #3:
100%
Accepted
Test #13:
score: 0
Runtime Error
input:
7 1 731039 314313205082038759
output:
Unauthorized output
result:
Subtask #8:
score: 0
Wrong Answer
Test #33:
score: 0
Wrong Answer
time: 154ms
memory: 81640kb
input:
8 9963 251 831797004675585320 494759973681332858 701341496127272302 252910460485222469 250965009655458584 366193481309061299 633134388675839346 791999098066205672 196620805863610860 363773642045280947 466508590762410710 407790578717064135 181590911404670570 570642047249889864 70138464625729452 23634...
output:
3 8 104 25 58 150 167 250 12 12 105 238 163 217 111 134 56 103 163 38 122 78 107 241 244 194 241 177 24 41 62 173 250 57 170 201 248 36 198 39 21 132 205 59 109 100 218 47 143 181 73 249 100 187 119 64 206 189 33 107 157 185 0 34 188 217 73 89 115 6 184 216 123 202 97 170 169 48 187 175 46 172 189 2...
result:
wrong answer 1st numbers differ - expected: '0', found: '3'
Subtask #9:
score: 0
Skipped
Dependency #2:
0%