QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#21423#2819. 摆家具gogoTL 2377ms316020kbC++203.7kb2022-03-04 22:58:512022-05-08 03:14:01

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-08 03:14:01]
  • 评测
  • 测评结果:TL
  • 用时:2377ms
  • 内存:316020kb
  • [2022-03-04 22:58:51]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l); i <= (r); i ++)
#define per(i, r, l) for(int i = (r); i >= (l); i --)
#define trv(i, u, v) for(int i = head[u], v = e[i].to; i; v = e[i = e[i].nxt].to)
#define fi first
#define se second
#define all(s) s.begin(), s.end()
#define sz(s) (int)(s.size())
#define lb(s) ((s) & -(s))
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
mt19937_64 hua(time(0));
template<typename T> inline bool chkmx(T &x, T y) {return x < y ? x = y, 1 : 0;}
template<typename T> inline bool chkmn(T &x, T y) {return y < x ? x = y, 1 : 0;}
template<int T> using A = array<int, T>;

inline ll read() {
	ll x = 0, f = 1; char c = getchar();
	for(; !isdigit(c); c = getchar()) if(c == '-')  f = 0;
	for(; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	return f ? x : -x;
}
const int maxn = 1e6;
const int maxk = 20;
//const int B = 1e5;
const int B = 3e3; 
const int mod = 998244353;
int n, k, q, N, pw[maxk + 5], w[maxn + 5];
int fac[maxk + 5], ifac[maxk + 5], inv[maxk + 5];
int f[maxn + 5][maxk + 5], g[maxn + 5][maxk + 5], h[maxn + 5][maxk + 5];
inline int add(int a, int b) {return (a += b) >= mod ? a - mod : a;}
inline int sub(int a, int b) {return (a -= b) < 0 ? a + mod : a;} 
inline int mul(int a, int b) {return 1ll * a * b % mod;}
inline void upd(int &a, int b) {a = add(a, b);}
inline int fpw(int a, int b) {
	int ans = 1;
	for(; b; b >>= 1, a = mul(a, a)) if(b & 1) ans = mul(ans, a);
	return ans;
}
struct Mat {
	int a[maxk + 1][maxk + 1];
	int* operator [] (int x) {return a[x];}
	Mat() {memset(a, 0, sizeof a);}
	friend Mat operator * (Mat x, Mat y) {
		Mat z;
		rep(i, 0, k) rep(j, 0, k) rep(l, 0, k) {
			upd(z[i][j], mul(x[i][l], y[l][j]));
		}
		return z;
	}
}mpw1[B + 5], mpw2[B + 5], mpw3[B + 5];
void init() {
	fac[0] = fac[1] = inv[0] = inv[1] = ifac[0] = ifac[1] = 1;
	rep(i, 2, maxk) fac[i] = mul(fac[i - 1], i);
	rep(i, 2, maxk) inv[i] = mul(inv[mod % i], mod - mod / i);
	rep(i, 2, maxk) ifac[i] = mul(ifac[i - 1], inv[i]); 
}
inline int c(int n, int m) {return mul(fac[n], mul(ifac[m], ifac[n - m]));} 
int main() {
	//freopen("in.txt", "r", stdin);
	n = read(), k = read(), q = read();
	N = fpw(n, k);
	pw[0] = 1;
	init();
	rep(i, 1, k) pw[i] = pw[i - 1] * n;
	rep(i, 0, N - 1) f[i][0] = w[i] = read();
	rep(i, 0, k - 1) {
		memcpy(g, f, sizeof g);
		memcpy(h, f, sizeof h);
		per(s, N - 1, 0) {
			rep(j, 0, k) {
				if(s / pw[i] % n != n - 1) {
					upd(g[s][j], g[s + pw[i]][j]);
				}
			}
		}
		rep(s, 0, N - 1) {
			rep(j, 0, k) {
				if(s / pw[i] % n != 0) {
					upd(h[s][j], h[s - pw[i]][j]);
				}
			}
		}
		rep(s, 0, N - 1) {
			per(j, k, 0) {
				f[s][j] = 0;
				if(s / pw[i] % n != 0) upd(f[s][j], h[s - pw[i]][j]);
				if(s / pw[i] % n != n - 1) upd(f[s][j], g[s + pw[i]][j]);
				if(j) upd(f[s][j], f[s][j - 1]);
			}
		}
	}
//	rep(i, 0, N - 1) {
//		rep(j, 0, k) {
//			cout << g[i][j] << " \n"[j == k];
//		}
//	}
	Mat bs;
	rep(i, 0, k) {
		bs[i][i] = mul(k - i, n - 2);
		mpw1[0][i][i] = mpw2[0][i][i] = mpw3[0][i][i] = 1;
	}
	rep(i, 1, k) {
		bs[i][i - 1] = mul(i, n - 1);
	}
	rep(i, 0, k - 1) {
		bs[i][i + 1] = k - i;
	}
	rep(i, 1, B) {
		mpw1[i] = mpw1[i - 1] * bs;
	}
	rep(i, 1, B) {
		mpw2[i] = mpw2[i - 1] * mpw1[B];
	}
	rep(i, 1, B) {
		mpw3[i] = mpw3[i - 1] * mpw2[B];
	}
	ll lstans = 1;
	rep(i, 1, q) {
		ll a = read(), t = read() * lstans % mod;
		int x = t / B % B, y = t % B, z = t / B / B, ans = 0;
		Mat cur = mpw3[z] * mpw2[x] * mpw1[y];
		rep(i, 0, k) {
//			cout << cur[k][i] <<  " \n"[i == k];
			upd(ans, mul(mul(cur[k][i], f[a][i]), fpw(mul(c(k, i), fpw(n - 1, k - i)), mod - 2)));
		}
		cout << (lstans = ans) << '\n';
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 520ms
memory: 242860kb

input:

6 7 23333
691899807
511100503
969237388
938904792
350428599
320423686
227132681
288051232
833056445
128207711
81740114
850060462
194951182
130925016
505452669
304380595
703105541
640122112
75295756
128144693
482592240
835507949
68960843
807876145
6134269
259053259
386495729
193956365
370675670
12980...

output:

190581075
197794774
345498162
59688720
168669317
841717697
342906119
137414971
825722766
29575707
853971537
278001951
268532266
37403931
437460694
620208693
66609375
403688722
976391048
491806503
298322771
631646293
927418682
648947221
68582150
226201662
207241545
17375057
263100976
540120514
433099...

result:

ok 23333 lines

Test #2:

score: 0
Accepted
time: 2377ms
memory: 316012kb

input:

10 6 499992
883981029
424184611
390644163
186684863
174728805
352881784
953947952
773609716
907239584
791751597
444938530
461456743
385730847
148399228
774687506
9709242
68881950
559913618
909120969
567290547
274910682
127146223
18334763
679114303
509060537
406621577
596834508
415847390
750748687
69...

output:

893356346
460269203
739618263
575487556
823262857
959075468
442981064
379364003
520589980
408419264
962089959
532443198
457198012
936755450
707631444
639551012
501722307
54986538
947539125
293051047
736520294
145839901
669179979
385018500
178607686
73569962
457986293
912015195
183765686
794760523
77...

result:

ok 499992 lines

Test #3:

score: 0
Accepted
time: 1849ms
memory: 291568kb

input:

15 5 500000
505484351
497688716
546731680
964754919
196294896
617209569
555560108
91152824
603611039
403851027
608394993
262605748
565802956
744734397
31623673
595290933
617664042
655289027
31029383
427106733
830003904
614943018
971450634
87580932
542657216
939674620
536263049
542852153
618447940
71...

output:

979878232
502012447
837375524
648850473
372016965
88786781
438815378
350532799
135130633
639465431
315342261
17918128
255399473
659394908
630493926
323082621
927511589
215929363
335530238
618826645
379739184
19810887
399268915
103084315
217968568
457352471
24987165
330231636
873809029
114633697
2862...

result:

ok 500000 lines

Test #4:

score: 0
Accepted
time: 1573ms
memory: 308200kb

input:

31 4 500000
873132748
143861990
476370579
290413250
321978338
924143354
837842213
858068823
893643188
350393336
974299396
66468900
161847648
160755624
630177685
15786978
742472523
692563064
814267336
933743581
685556394
210699804
718255928
65125157
974700737
476917926
883144754
873388830
260036915
7...

output:

117268813
819018523
776768369
741209449
744498590
120071025
226984394
90007863
939423845
878313441
304691338
392220263
127581724
439314464
26862504
346663422
650004724
251278984
108796604
971079803
327255877
256973834
227173217
985548913
506828616
633681752
131186964
812774711
116108044
169648841
40...

result:

ok 500000 lines

Test #5:

score: 0
Accepted
time: 1283ms
memory: 316020kb

input:

100 3 500000
69501783
983926132
677774943
69763238
229978802
740941191
539402529
154743577
751966051
2646498
224715922
118063086
627921580
898461795
955831727
416453873
14778043
516566032
564752940
181778667
854451334
950970458
936033583
922684013
152424128
328311215
790981818
702141983
966264407
85...

output:

184621141
886327200
681090353
449056824
781618881
115181957
426499945
260260962
911237835
965376439
300419966
589424733
123229266
785625549
546029984
442034899
388267896
684458618
195809458
20009458
426509673
122152893
2104958
463059830
352181528
643342912
486348781
458867324
19039301
353204424
6039...

result:

ok 500000 lines

Test #6:

score: 0
Accepted
time: 987ms
memory: 316016kb

input:

1000 2 500000
483290026
77460592
332660242
106703469
434234061
455058920
556238357
24497230
922071773
467490309
577534517
169507551
728487110
708808551
529347050
871686307
577270581
10179512
594316766
667127175
563057402
852990097
207199337
955310144
731674888
467932878
392176687
821799278
969377355...

output:

368958893
157223722
292796988
642533231
159133366
284998940
65555601
251111003
783103389
154739003
575815496
790581708
709356018
408854640
372526412
308805425
614598882
571166795
580052186
718818280
56736587
815690398
91494865
197050725
109336354
374333046
374458971
858752081
833475651
585345655
499...

result:

ok 500000 lines

Test #7:

score: 0
Accepted
time: 786ms
memory: 315992kb

input:

1000000 1 500000
251055524
454201434
742507937
933949296
5497634
524473780
533949826
813658703
436744366
549681279
833659165
960901932
125155782
833291726
346494758
56508523
996923766
123565531
774148853
874417054
484068183
433006936
695931450
752399778
337593593
43594090
829258152
664530824
5594933...

output:

326771917
535904675
965793060
549465552
384143458
278039901
957870727
127785253
210029827
892986539
784268197
776296487
551595915
749545280
264971517
253922166
789378018
185371966
568293778
272220006
322113820
429616722
602408789
912040965
171539430
943059113
485799881
852599179
773978550
869366175
...

result:

ok 500000 lines

Test #8:

score: 0
Accepted
time: 601ms
memory: 242404kb

input:

8 6 66666
762632409
278781514
983938354
215161563
825597216
334484655
896602072
349664404
791855251
519549984
535486218
722755687
976326824
780635505
740436130
731964947
676528034
358069017
168477195
921166389
469310971
305642123
903617163
278297809
268861284
87258643
487466490
446331721
887038434
1...

output:

435885311
791730460
394640664
75649208
641167408
622645423
585865614
673979813
215664794
946211062
813726822
173088040
382435698
736541474
742744192
129571340
355179929
982890533
370134926
164867173
403374726
393851117
898586967
24557503
469648925
716601758
484716413
925321022
886807109
332801791
40...

result:

ok 66666 lines

Test #9:

score: 0
Accepted
time: 299ms
memory: 216640kb

input:

12 4 55555
197178262
578999644
333173795
551118586
317399521
499956238
822139685
581307933
167129094
564412175
704862130
607776171
751153237
939551291
182286053
432731777
528429591
745229393
733266093
605324803
41983117
120383567
620780688
608752835
931257346
200024433
241498351
228791449
580080365
...

output:

661082746
815441729
100762693
294477597
736004158
439025524
879104083
292739355
43371968
866655117
274828007
545033662
715290768
794583370
636756659
491641439
872639006
848225686
971139705
674984253
78007132
88277942
644385137
672152403
707666118
220936700
458557694
8298591
499614459
91242274
778977...

result:

ok 55555 lines

Test #10:

score: 0
Accepted
time: 395ms
memory: 221756kb

input:

233 2 233333
268358199
873653363
469164977
484799852
130172856
468808868
855128475
884288087
813589312
418175909
160012718
482438225
546274631
681769076
939719128
910906006
150691738
170063927
712952591
433792439
459493770
1906569
779711173
261615079
761652883
456069570
312579657
340663490
844762847...

output:

735261715
695986226
342581903
89591047
982713738
126272926
530843418
830949156
695151160
460788630
199212163
681916027
306210097
214205027
872146063
255204872
570801958
374890385
899215195
250476623
519963882
217276010
344171156
458149854
507840400
378333793
968555287
360821807
496932371
804688371
5...

result:

ok 233333 lines

Test #11:

score: -100
Time Limit Exceeded

input:

2 19 500000
713448041
15755846
961811667
280573995
386148277
964323207
842485042
947749487
42983063
917443625
305236230
111429944
181915829
784845875
650459231
761824955
348455354
607083113
555660898
307955183
457192498
45086306
297195265
593232944
6222701
189812219
576174218
922820203
498943822
842...

output:

906680845
900549217
818081406
389518813
445683132
393302604
155882525
64171899
733623386
83773581
149450646
183110423
99395460
645381068
453263323
52843788
920622431
392549610
309316350
589696921
244881333
699277841
694794005
505675453
156731966
579544152
831461396
578062131
803022812
301499970
1015...

result: