QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#216912 | #5121. Square Grid | zhouhuanyi | AC ✓ | 2026ms | 105920kb | C++14 | 3.2kb | 2023-10-16 08:10:31 | 2023-10-16 08:10:32 |
Judging History
answer
#include<iostream>
#include<cstdio>
#define N 300000
#define M 524288
#define K 20
#define g 3
#define mod 998244353
using namespace std;
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
int fast_pows(int a,int b)
{
int res=1,mul=a;
while (b)
{
if (b&1) res=1ll*res*mul%mod;
mul=1ll*mul*mul%mod,b>>=1;
}
return res;
}
int MD(int x)
{
return x>=mod?x-mod:x;
}
int MD2(int x)
{
return x<0?x+mod:x;
}
void Adder(int &x,int d)
{
x+=d;
if (x>=mod) x-=mod;
return;
}
void Adder2(int &x,int d)
{
x+=d;
if (x<0) x+=mod;
return;
}
struct reads
{
int d[N+1];
};
reads e,c,zero,nw,res;
int n,m,length,T,q,ans,num[M+1],A[M+1],B[M+1],rev[M+1],s[M+1],wn[K+1][M+1],wn2[K+1][M+1];
inline void NTT(int limit,int *s,int type)
{
int s1,s2;
for (int i=1;i<limit;++i)
if (rev[i]>i)
swap(s[i],s[rev[i]]);
if (type==1)
{
for (int i=2,w;i<=limit;i<<=1)
for (int j=0;j+i-1<limit;j+=i)
for (int k=j;k<j+(i>>1);++k)
s1=s[k],s2=1ll*s[k+(i>>1)]*wn[num[i]][k-j]%mod,s[k]=MD(s1+s2),s[k+(i>>1)]=MD2(s1-s2);
}
else
{
for (int i=2,w;i<=limit;i<<=1)
for (int j=0;j+i-1<limit;j+=i)
for (int k=j;k<j+(i>>1);++k)
s1=s[k],s2=1ll*s[k+(i>>1)]*wn2[num[i]][k-j]%mod,s[k]=MD(s1+s2),s[k+(i>>1)]=MD2(s1-s2);
s1=fast_pows(limit,mod-2);
for (int i=0;i<=limit;++i) s[i]=1ll*s[i]*s1%mod;
}
return;
}
int limit=1;
inline reads operator * (reads a,reads b)
{
for (int i=0;i<=limit;++i) A[i]=B[i]=0;
for (int i=0;i<m;++i) A[i]=a.d[i],B[i]=b.d[i];
NTT(limit,A,1),NTT(limit,B,1);
for (int i=0;i<=limit;++i) A[i]=1ll*A[i]*B[i]%mod;
NTT(limit,A,-1);
for (int i=0;i<m;++i) c.d[i]=MD(A[i]+A[i+m]);
return c;
}
inline reads solve(reads a)
{
for (int i=0;i<=limit;++i) A[i]=0;
for (int i=0;i<m;++i) A[i]=a.d[i];
NTT(limit,A,1);
for (int i=0;i<=limit;++i) A[i]=1ll*A[i]*A[i]%mod;
NTT(limit,A,-1);
for (int i=0;i<m;++i) c.d[i]=MD(A[i]+A[i+m]);
return c;
}
reads fast_pow(reads a,int b)
{
reads res=e,mul=a;
while (b)
{
if (b&1) res=res*mul;
mul=solve(mul),b>>=1;
}
return res;
}
int calc(int x,int y)
{
if ((x+y+T)&1) return 0;
int sx=((x+y+T)>>1)%m,sy=(((x-y+T)>>1)+m)%m;
return MD(1ll*res.d[sx]*res.d[sy]%mod+1ll*res.d[(sx+(m>>1))%m]*res.d[(sy+(m>>1))%m]%mod);
}
int main()
{
int xs,ys,xt,yt;
n=read(),T=read(),q=read(),m=(n<<1)+4,e.d[0]=nw.d[0]=nw.d[1]=1;
while (limit<=(m<<1)) limit<<=1;
for (int i=1;i<limit;++i) rev[i]=(rev[i>>1]>>1)|((i&1)?(limit>>1):0);
for (int i=2,w;i<=limit;i<<=1)
{
num[i]=++length,w=fast_pows(g,(mod-1)/i);
for (int j=0,res=1;j<(i>>1);++j,res=1ll*res*w%mod) wn[num[i]][j]=res;
w=fast_pows(g,(mod-1)/i*(i-1));
for (int j=0,res=1;j<(i>>1);++j,res=1ll*res*w%mod) wn2[num[i]][j]=res;
}
res=fast_pow(nw,T);
while (q--)
{
xs=read(),ys=read(),xt=read(),yt=read(),ans=0;
Adder(ans,calc((xt+m-xs)%m,(yt+m-ys)%m));
Adder2(ans,-calc((((n+1)<<1)-xt+m-xs)%m,(yt+m-ys)%m));
Adder2(ans,-calc((xt+m-xs)%m,(((n+1)<<1)-yt+m-ys)%m));
Adder(ans,calc((((n+1)<<1)-xt+m-xs)%m,(((n+1)<<1)-yt+m-ys)%m));
printf("%d\n",ans);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 41648kb
input:
2 5 3 0 0 1 2 1 1 2 1 0 0 2 2
output:
30 64 0
result:
ok 3 number(s): "30 64 0"
Test #2:
score: 0
Accepted
time: 4ms
memory: 41656kb
input:
5 20 5 0 0 5 5 1 1 4 4 2 2 3 3 2 3 2 3 1 2 5 2
output:
615136704 443203969 899931333 464755094 679729107
result:
ok 5 number(s): "615136704 443203969 899931333 464755094 679729107"
Test #3:
score: 0
Accepted
time: 0ms
memory: 45692kb
input:
10 10 100 9 3 0 6 10 10 4 4 10 1 2 6 7 8 2 3 0 3 9 2 3 6 1 10 1 5 2 9 7 3 1 5 9 10 3 0 0 6 9 3 0 8 2 0 3 10 8 1 9 7 8 2 1 0 7 6 5 8 4 2 2 5 0 7 8 6 7 5 4 2 3 7 10 3 1 10 5 6 5 0 9 1 3 5 7 6 5 7 7 5 0 10 3 1 8 8 4 0 2 4 5 7 3 9 6 2 6 9 6 7 10 3 10 9 5 10 3 5 7 5 6 5 7 0 2 10 6 9 0 9 4 1 7 6 9 4 6 8 5...
output:
0 0 0 252 10 8040 0 1200 0 0 45 0 5148 0 0 20790 52470 5400 0 1925 210 0 0 0 8250 29040 0 2310 2970 14400 4950 0 0 29040 5400 0 29040 0 2520 8250 0 0 0 0 1155 7392 0 2310 0 320 0 29700 1980 0 63404 0 0 42075 27710 0 0 2520 5544 0 63403 24750 0 45 2310 13860 5544 52900 11340 6930 19800 0 3300 5138 25...
result:
ok 100 numbers
Test #4:
score: 0
Accepted
time: 19ms
memory: 60028kb
input:
100 998244353 100000 30 78 89 46 12 26 33 24 16 4 68 89 51 48 88 35 12 83 76 24 73 11 48 13 89 3 13 15 67 61 56 85 47 13 96 33 59 38 71 37 67 37 35 20 85 26 1 19 38 90 14 41 7 52 66 64 68 6 13 66 78 28 50 84 15 35 98 87 44 0 55 82 50 74 56 49 88 98 75 74 6 5 18 18 90 75 16 17 17 74 91 11 57 41 17 14...
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 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 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 ...
result:
ok 100000 numbers
Test #5:
score: 0
Accepted
time: 7ms
memory: 35460kb
input:
1 234567890 100 1 1 0 0 0 0 1 0 0 1 0 1 0 0 0 0 1 1 0 0 1 0 0 1 1 0 0 1 1 1 1 1 0 1 1 1 1 1 0 1 0 0 0 0 0 0 1 0 0 1 1 0 1 0 1 1 0 1 1 0 0 0 1 1 1 1 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 1 0 0 1 0 0 1 1 1 1 1 1 1 1 0 0 1 1 0 0 0 0 0 1 0 0 1 0 1 1 0 1 1 0 0 0 0 0 0 0 0 0 1 0 0 1 1 0 1 1 0 0 0 0 0 0 0 0 0 0 1 ...
output:
562097306 0 562097306 562097306 562097306 562097306 562097306 562097306 0 0 562097306 0 562097306 0 562097306 562097306 562097306 562097306 0 0 562097306 562097306 562097306 0 562097306 562097306 562097306 562097306 562097306 562097306 0 562097306 562097306 562097306 562097306 562097306 562097306 56...
result:
ok 100 numbers
Test #6:
score: 0
Accepted
time: 1414ms
memory: 99480kb
input:
100000 1000000000 300000 401 24053 58285 18046 98210 71066 13326 96996 35754 75165 22182 67209 34695 62569 98038 25962 25823 83198 3812 44322 40127 22699 32134 158 2721 51519 79219 46775 71309 3160 73856 6217 75906 67973 22027 11684 93792 19353 432 89701 26433 63842 6090 20535 49837 36247 57729 4509...
output:
0 379704143 484336286 586267688 0 802945105 331035905 684439572 266643694 937973312 193562977 900135476 639560782 257961403 0 477150844 665589389 73169218 738148457 152843659 42310826 954467545 0 560643872 0 918083639 292414014 0 21258635 422256444 390404559 385900331 360521148 206632235 171640929 7...
result:
ok 300000 numbers
Test #7:
score: 0
Accepted
time: 1290ms
memory: 103884kb
input:
99997 910438092 300000 32817 10624 69074 15628 62279 5945 8226 81160 72515 87825 31901 95673 74725 85377 81141 21641 41979 73405 99333 11589 1268 7217 44281 45740 27532 81539 43139 25522 2036 11940 23175 11249 98765 82650 4175 18626 48459 62818 1786 88335 42311 33767 1829 99111 28160 54081 54753 457...
output:
0 598595670 503636826 911727380 86220503 222325861 453201104 983921025 652997497 650447287 698471859 260090020 0 142166962 89437772 291868078 232663170 253682040 956911869 121225784 133201708 28557946 0 482392784 149467031 56711917 675597121 559227759 705913570 897100630 588562195 407850400 98046497...
result:
ok 300000 numbers
Test #8:
score: 0
Accepted
time: 2026ms
memory: 100580kb
input:
86329 536870911 100000 6934 39570 29812 483 23213 80961 77391 77464 35711 44128 25269 66517 12740 13175 43393 37797 49868 36732 74533 46280 19920 20482 18043 19515 84452 36416 9447 49472 17854 14354 69872 13632 43952 77429 54828 72724 43512 34010 34581 79197 21653 53038 42903 66166 82034 57844 30368...
output:
920551961 667989346 234860149 772573120 52432323 0 718118104 0 92461711 0 0 992815562 587706672 848791478 0 807031646 0 169787279 737215243 80849342 322874478 758152365 265527504 507915769 131833668 967939168 532302541 759821594 867528836 553484567 536451252 299154350 102135044 850966692 237786120 5...
result:
ok 100000 numbers
Test #9:
score: 0
Accepted
time: 1332ms
memory: 99140kb
input:
65534 751851044 45678 18597 2705 38264 9926 60579 43128 63162 55019 53286 50546 63261 51451 52904 38687 44496 4213 40258 12970 56854 43670 29287 50367 6106 49211 39973 58844 58488 60677 18862 48347 15244 26255 13345 14217 44510 33208 25128 51573 34150 31373 18129 1028 55527 32106 18207 44310 55675 3...
output:
566443736 913113315 243594181 76226628 173140575 0 873101601 70039719 124620611 32027083 389726888 0 334708694 412646728 630095765 643719216 971502592 662540236 105047884 45413740 83458692 513147289 0 362632343 572745734 173258523 238192596 0 0 231766088 707734804 95357690 770547266 108450694 852446...
result:
ok 45678 numbers
Test #10:
score: 0
Accepted
time: 781ms
memory: 105920kb
input:
100000 55555 300000 20396 24388 78812 88866 95707 68397 75780 93359 32040 21598 35816 81149 78307 69401 94059 26138 19436 5712 11695 4924 64724 62688 98663 79134 47600 57898 27107 23406 91318 35669 88672 18518 22702 68979 29580 29514 41061 64644 1339 41725 80480 19766 49919 63198 36324 94593 44738 1...
output:
0 275628277 0 0 494058578 586628787 605925258 976940870 867641159 0 0 0 0 0 0 971356822 915424518 0 0 0 0 0 0 0 780786512 0 0 0 472991301 0 0 792444873 0 246191870 863773698 0 323569439 0 751080645 244539728 0 918682152 0 47179876 0 3626284 854406731 846659000 0 0 15089419 926828326 0 0 0 0 0 0 8263...
result:
ok 300000 numbers
Test #11:
score: 0
Accepted
time: 200ms
memory: 88960kb
input:
10000 924833031 299995 9918 7760 4469 639 9918 1931 8393 8309 5279 5339 9742 2961 702 2641 9687 5105 3284 2528 4263 9670 894 8929 4185 6779 3114 593 5604 7146 5588 8338 1112 9441 1313 2022 6977 3601 1865 2247 9208 1237 845 5848 2854 2867 5142 8745 8641 5699 2979 9025 9437 9431 2845 315 6971 9850 852...
output:
0 503252406 757927813 258680970 823065682 428632582 252270838 172749780 464314759 905078645 0 114440877 0 923267567 0 634672699 37589468 0 972371769 493906633 338609633 0 585322372 0 574702336 409668159 0 0 719995804 10776705 0 719626401 568790569 618889479 565039624 453186973 568958138 841503027 39...
result:
ok 299995 numbers
Test #12:
score: 0
Accepted
time: 85ms
memory: 80628kb
input:
3000 987654321 262144 323 1997 2896 961 1433 2329 884 1493 1490 500 1210 2969 726 2199 2885 2283 2358 668 2155 1942 1411 2046 1513 2061 1590 2621 132 98 414 896 1169 2136 954 2298 76 1063 773 156 2688 2030 173 619 1341 580 2865 1065 118 1057 92 521 557 2763 232 68 2498 2265 2482 905 2257 417 2423 22...
output:
729177672 60896210 913367239 670671209 168185271 549330697 969671753 526931546 556301122 987786600 129834745 271039522 689587076 162824733 417039374 348262929 867741829 278632822 694064713 0 0 755495492 986726730 711255634 533281118 99370177 0 673381719 885844707 216423652 813377063 360839188 278376...
result:
ok 262144 numbers