QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#800697#9847. Security PlandxbtAC ✓168ms3868kbC++141.3kb2024-12-06 14:38:332024-12-06 14:38:34

Judging History

This is the latest submission verdict.

  • [2024-12-06 14:38:34]
  • Judged
  • Verdict: AC
  • Time: 168ms
  • Memory: 3868kb
  • [2024-12-06 14:38:33]
  • Submitted

answer

#include<bits/stdc++.h>
#define pii pair<ll,ll>
#define x first
#define y second
#define mp(x,y) make_pair(x,y)
#define ep emplace_back
using namespace std;
typedef __int128 ll;
constexpr int mod=998244353;
ll C2(ll n)
{
	return (ll)n*(n-1)/2;
}
ll qpow(ll x,ll y)
{
	ll res=1;
	while(y)
	{
		if(y&1)res=1ll*res*x%mod;
		x=1ll*x*x%mod;
		y>>=1;
	}
	return res;
}
ll sk(ll x)
{
	if(x<0)return 0;
	//cout<<x*(1+x)*x/2<<'-'<<1ll*x*(x+1)*(2*x+1)%mod*qpow(6,mod-2)%mod<<'\n';
	return (1ll*x*(1+x)%mod*x*qpow(2,mod-2)%mod+mod-1ll*x*(x+1)%mod*(2*x+1)%mod*qpow(6,mod-2)%mod)%mod;
}
signed main()
{
	cin.tie(0)->sync_with_stdio(false);
	ll T;int t;
	cin>>t;T=t;
	while(T--)
	{
		ll n,m;int x;
		cin>>x;n=x;
		cin>>x;m=x;
		ll a=4-2*(min(n,m)==1);
		ll b=n+m+n+m-4-a;
		if(min(n,m)==1) b=(n+m-3);
		ll c=n*m-a-b;
		if(n==1&&m==1)
		{
			cout<<1<<'\n';
			continue;
		}
		if(min(n,m)==1)
		{
			cout<<(int)((2+C2((1ll*n*m-2)%mod))%mod)<<'\n';;
			continue;
		}
		ll ans=(c-1)*(c-2)%mod*(c-3)%mod*(c)%mod*qpow(24,mod-2)%mod;
		ans+=4;
		ans+=C2(2*(n-2))+C2((m-2)*2);
		ans=(ans+2ll*(n-2)*2*(m-2)%mod*c)%mod;
		ans+=2*(n-2+m-2)*C2((n-2)*(m-2)%mod)%mod;
		ans=(ans+(mod-1ll)*2%mod*(m-2)*(m-2)%mod*sk(n-5))%mod;
		ans=(ans+(mod-1ll)*2%mod*(n-2)*(n-2)%mod*sk(m-5))%mod;
		cout<<((int)ans)<<'\n';
	}
	return 0;
}


这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3600kb

input:

6
2 2
4 4
8 8
3 3
3 5
3 7

output:

4
129
78769
10
80
273

result:

ok 6 numbers

Test #2:

score: 0
Accepted
time: 1ms
memory: 3580kb

input:

32
1 1
1 2
1 3
1 4
1 10
1 1000000000
2 1
2 2
2 3
2 4
2 11
2 1000000000
3 1
3 2
3 3
3 4
3 13
3 1000000000
4 1
4 2
4 3
4 4
4 101
4 1000000000
1000000000 1000000000
998244353 998244353
998244353 1000000000
10086 2333333
10007 1000007
5 5
100000000 99999999
100000000 999999999

output:

1
2
2
3
30
852768513
2
4
5
10
157
418096634
2
5
10
33
2202
167942187
3
10
33
129
65053470
16765744
97600132
361
767496180
544716794
658473844
916
507579369
838777510

result:

ok 32 numbers

Test #3:

score: 0
Accepted
time: 1ms
memory: 3572kb

input:

100
69 34
89 48
75 22
87 3
83 39
57 75
33 51
95 27
60 77
36 89
16 41
71 15
90 100
11 55
22 6
12 27
8 90
87 30
10 66
10 77
64 72
34 59
85 10
71 69
91 26
100 26
83 7
24 40
7 26
58 18
34 78
10 76
63 53
69 34
18 88
5 74
97 23
23 5
29 7
32 33
63 10
68 90
11 42
82 52
24 71
57 43
97 100
24 96
18 62
72 49
8...

output:

844735252
345907935
28586429
2498333
488377238
942953328
487609202
6387550
705350958
854342223
681010480
891769844
675198269
144965651
1733560
160888719
226806279
351471008
848277946
378038496
869514320
719885729
71253797
881211829
821932261
570789100
117004990
276160389
8609315
766887746
62835495
9...

result:

ok 100 numbers

Test #4:

score: 0
Accepted
time: 2ms
memory: 3680kb

input:

1000
693 448
522 128
734 292
39 500
674 488
741 349
435 16
387 539
83 110
946 88
252 343
498 621
329 428
138 947
666 186
380 147
164 386
206 823
455 442
738 342
670 481
798 212
114 983
125 55
616 867
205 619
606 995
103 847
138 32
706 174
779 879
865 368
918 985
440 718
938 379
930 601
700 919
278 3...

output:

734353341
123938970
638720098
99480889
45755531
60438254
334240489
328423327
69642545
329776145
449587504
631740095
420016666
766086244
682367864
63393960
539316316
598272575
609449562
518346062
108580099
53857412
377251971
463895994
279595152
857916396
156295957
715834409
253131435
747142668
913120...

result:

ok 1000 numbers

Test #5:

score: 0
Accepted
time: 2ms
memory: 3524kb

input:

1000
646649471 300856132
258546501 856735895
1054383 618481963
714454302 553857681
543357466 560569528
745974354 814790544
656224737 283726575
223167186 831188152
229958118 242031417
296164244 478306773
190085456 370448866
538531088 584661972
61581579 818790042
796453827 612078408
136485445 67908120...

output:

936356743
692738897
536334664
497090628
137405835
855341208
850122060
737685630
859446507
10183890
629672738
730330292
188163195
755395630
583537380
3897190
198375879
674478313
962103461
869673891
440733315
127511280
142196279
462988628
201262486
592926610
353724472
705491421
546217368
683992452
214...

result:

ok 1000 numbers

Test #6:

score: 0
Accepted
time: 166ms
memory: 3868kb

input:

100000
396087033 851919454
272633663 693544215
134154950 652656189
572487516 700424176
500239593 176117565
251559708 968180827
286792006 501694258
342854277 136982556
147170341 985222382
238365250 53658681
311527089 715587788
363840544 556012925
75173755 702572328
235770257 837485304
213435639 91300...

output:

680415885
854935562
574194455
239752979
295195100
862556107
205771842
157078195
246006763
849343117
738262223
518017375
317538920
755353940
788239273
725428685
37245154
128920658
785353768
417644088
581116546
308678670
173043566
614160812
266567568
383295052
349329429
980197306
869343217
717063770
7...

result:

ok 100000 numbers

Test #7:

score: 0
Accepted
time: 161ms
memory: 3800kb

input:

100000
141 552
445 281
351 965
848 67
708 702
236 988
880 666
775 808
470 497
53 415
921 349
701 957
59 780
987 123
145 320
572 148
244 246
124 9
881 147
803 422
226 98
155 963
732 783
644 915
399 55
905 608
985 765
817 877
387 55
270 491
618 511
769 477
631 756
372 251
232 38
414 19
653 901
19 779
...

output:

462670722
525054817
588971520
246101914
767097239
54039137
68465875
169533373
300956005
209697526
2281163
351373025
707330016
555515039
744893104
556993562
867719289
114924088
789158994
586794116
181129766
104044094
617021562
641329389
49555278
840018038
275473284
671034111
930430062
108764006
67400...

result:

ok 100000 numbers

Test #8:

score: 0
Accepted
time: 166ms
memory: 3572kb

input:

100000
95757457 168696057
246194599 657776891
721156035 295216522
60141839 173897297
72142203 996520448
705437541 22492882
892105150 145550294
141786412 390498407
525334887 390855102
450494213 387351110
110666886 137920825
822826658 335003085
751220980 391407057
977029072 807147061
678325259 4081747...

output:

841734664
266392797
915756132
488589632
366286363
569533466
418200644
49784864
586836466
953367262
39878281
407231429
572711059
198744422
891563192
661883015
670225249
790514058
536400309
388009226
926674932
497723196
260029955
241774909
588362447
151947289
397470378
717751986
224513327
902434342
50...

result:

ok 100000 numbers

Test #9:

score: 0
Accepted
time: 71ms
memory: 3632kb

input:

44100
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59
1 60
1 6...

output:

1
2
2
3
5
8
12
17
23
30
38
47
57
68
80
93
107
122
138
155
173
192
212
233
255
278
302
327
353
380
408
437
467
498
530
563
597
632
668
705
743
782
822
863
905
948
992
1037
1083
1130
1178
1227
1277
1328
1380
1433
1487
1542
1598
1655
1713
1772
1832
1893
1955
2018
2082
2147
2213
2280
2348
2417
2487
2558...

result:

ok 44100 numbers

Test #10:

score: 0
Accepted
time: 168ms
memory: 3580kb

input:

100000
999999501 999999501
999999501 999999502
999999501 999999503
999999501 999999504
999999501 999999505
999999501 999999506
999999501 999999507
999999501 999999508
999999501 999999509
999999501 999999510
999999501 999999511
999999501 999999512
999999501 999999513
999999501 999999514
999999501 999...

output:

518655944
786085183
529126368
372145282
306767828
690124382
248361087
69617265
609292358
691801575
505308951
603482994
907252332
704805713
648080711
756275020
415846454
377001653
757207377
42946153
80938040
88674511
647395865
707358168
582566312
952529662
865773350
734571334
338457692
820715328
6953...

result:

ok 100000 numbers

Test #11:

score: 0
Accepted
time: 0ms
memory: 3856kb

input:

64
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
2 1
2 2
2 3
2 4
2 5
2 6
2 7
2 8
3 1
3 2
3 3
3 4
3 5
3 6
3 7
3 8
4 1
4 2
4 3
4 4
4 5
4 6
4 7
4 8
5 1
5 2
5 3
5 4
5 5
5 6
5 7
5 8
6 1
6 2
6 3
6 4
6 5
6 6
6 7
6 8
7 1
7 2
7 3
7 4
7 5
7 6
7 7
7 8
8 1
8 2
8 3
8 4
8 5
8 6
8 7
8 8

output:

1
2
2
3
5
8
12
17
2
4
5
10
19
32
49
70
2
5
10
33
80
158
273
432
3
10
33
129
334
700
1287
2171
5
19
80
334
916
2042
3991
7123
8
32
158
700
2042
4824
9910
18420
12
49
273
1287
3991
9910
21144
40418
17
70
432
2171
7123
18420
40418
78769

result:

ok 64 numbers

Test #12:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

1
1 3072038

output:

1

result:

ok 1 number(s): "1"

Extra Test:

score: 0
Extra Test Passed