QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#68182#5121. Square GridchenshiAC ✓1765ms12016kbC++142.1kb2022-12-15 00:14:062022-12-15 00:14:08

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-15 00:14:08]
  • 评测
  • 测评结果:AC
  • 用时:1765ms
  • 内存:12016kb
  • [2022-12-15 00:14:06]
  • 提交

answer

#include<cstdio>
#include<iostream>
using namespace std;
const int o=6e5,MOD=998244353;
inline int fix(int x){return x+(x>>31&MOD);}
inline int qp(int b,int f){int res=1;for(;f;f>>=1,b=b*1ll*b%MOD) if(f&1) res=res*1ll*b%MOD;return res;}
int n,T,q,bt=19,w[o],rev[o],coef[o],z[o];
//coef:(x+1)^t%(x^(2n+4)-1)
inline void init(){
	w[1<<(bt-1)]=1;
	for(int i=(1<<(bt-1))+1,j=qp(3,(MOD-1)/(1<<bt));i<(1<<bt);++i) w[i]=w[i-1]*1ll*j%MOD;
	for(int i=(1<<(bt-1));i--;) w[i]=w[i<<1];
	for(int i=1;i<(1<<bt);++i) rev[i]=((rev[i>>1]>>1)|((i&1)<<(bt-1)));
}
inline void ntt(int*a,int n,bool inv){
	for(int i=1;i<n;++i) if(rev[i]<i) swap(a[i],a[rev[i]]);
	for(int md=1;md<n;md<<=1) for(int i=0;i<n;i+=md<<1) for(int j=0,x,y;j<md;++j)
		x=a[i+j],y=a[i+j+md]*1ll*w[j+md]%MOD,a[i+j]=fix(x+y-MOD),a[i+j+md]=fix(x-y);
	if(inv) for(int i=1,j=n-1;i<j;swap(a[i++],a[j--]));
}
inline void maintain(int*a){
	ntt(a,1<<bt,1);
	for(int i=0,j=qp(1<<bt,MOD-2);i<(1<<bt);++i) a[i]=a[i]*1ll*j%MOD;
	for(int i=(1<<bt)-1,j=2*n+4;i>=j;--i) a[i-j]=fix(a[i-j]+a[i]-MOD),a[i]=0;
}
inline int calc(int x,int y){
	x+=y;y=x-2*y;
	return (coef[(x+T+4*n+8)/2%(2*n+4)]*1ll*coef[(y+T+4*n+8)/2%(2*n+4)]+coef[(x+T+2*n+4)/2%(2*n+4)]*1ll*coef[(y+T+2*n+4)/2%(2*n+4)])%MOD;
}
//翻折容斥,横向和竖向的翻折是独立的,且横向和竖向的翻折分别都是上下交错的
//x'=x+y,y'=x-y是旋转45度,这样两个方向独立
//先上翻再下翻x+=2n+4,即x'+=n+2,y'+=n+2,别的方向同理,发现x'-y'模2n+4不变,x'%(n+2)和y'%(n+1)不变且范围内合法的(x',y')通过合理翻折都存在恰一种方式达到
int main(){
	scanf("%d%d%d",&n,&T,&q);init();
	coef[0]=z[0]=z[1]=1;
	for(int t=T;t;t>>=1,maintain(z)){
		ntt(z,1<<bt,0);
		if(t&1){
			ntt(coef,1<<bt,0);
			for(int i=0;i<(1<<bt);++i) coef[i]=coef[i]*1ll*z[i]%MOD;
			maintain(coef);
		}
		for(int i=0;i<(1<<bt);++i) z[i]=z[i]*1ll*z[i]%MOD;
	}
	for(int X0,Y0,X1,Y1;q--;){
		scanf("%d%d%d%d",&X0,&Y0,&X1,&Y1);
		if((X0+Y0+X1+Y1)%2!=T%2) printf("0\n");
		else printf("%lld\n",(calc(X1-X0,Y1-Y0)+0ll+MOD-calc(n*2+2-X1-X0,Y1-Y0)+MOD-calc(X1-X0,n*2+2-Y1-Y0)+calc(n*2+2-X1-X0,n*2+2-Y1-Y0))%MOD);
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 148ms
memory: 11732kb

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: 209ms
memory: 11836kb

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: 172ms
memory: 11792kb

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: 1093ms
memory: 12008kb

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: 1334ms
memory: 12016kb

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: 1436ms
memory: 11796kb

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: 1390ms
memory: 11788kb

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: 1765ms
memory: 11772kb

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: 1221ms
memory: 11972kb

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: 825ms
memory: 11840kb

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: 1582ms
memory: 11896kb

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: 1535ms
memory: 11968kb

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