QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#202537#1831. BruteforcericofxWA 1050ms101336kbC++145.8kb2023-10-06 11:08:582023-10-06 11:08:58

Judging History

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

  • [2023-10-06 11:08:58]
  • 评测
  • 测评结果:WA
  • 用时:1050ms
  • 内存:101336kb
  • [2023-10-06 11:08:58]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll = long long;

#define int long long
const int mod = 998244353;
const int N = 1e5 + 5, M = 1e5;

int n, k, w, q;
int a[N];

int tr[N], sum[N][6];
void add(int x, int v) {
	x++;
	for (; x <= M; x += x & -x) tr[x] += v;
}
int qry(int x) {
	x++;
	int res = 0;
	for (; x; x -= x & -x) res += tr[x];
	return res;
}

int fpow(int a, int b, int mod) {
	int res = 1;
	for (; b; b >>= 1, a = a * 1ll * a % mod) if (b & 1) res = res * 1ll * a % mod;
	return res;
}
#define lson ((p << 1))
#define rson ((p << 1) | 1)
#define mid ((l + r) >> 1)
struct Tree1 {
	int cnt[N << 2][6][6], tag[N << 2], tmp[6][6];
	int pre[6];
	void pushup(int p) {
		for (int i = 0; i < w; i++) {
			for (int j = 0; j < w; j++) cnt[p][i][j] = cnt[lson][i][j] + cnt[rson][i][j];
		}
	}
	void build(int p, int l, int r) {
		if (l == r) {
			int ll = qry(l - 1), rr = qry(l);
			if (ll == rr) return;
			++ll;
			int xx = l % w;
			for (int i = ll; i <= rr; i++) cnt[p][xx][i % w]++;
			return;
		}
		build(lson, l, mid), build(rson, mid + 1, r);
		pushup(p);
	}
	void pushdown(int p) {
		if (tag[p] == 0) return;
		int &x = tag[p];
		int xx = x % w;
		for (int j = 0; j < w; j++) pre[j] = (j + xx + w) % w;
		for (int i = 0; i < w; i++)
			for (int j = 0; j < w; j++) tmp[i][pre[j]] = cnt[lson][i][j];
		for (int i = 0; i < w; i++)
			for (int j = 0; j < w; j++) cnt[lson][i][j] = tmp[i][j];
		for (int i = 0; i < w; i++)
			for (int j = 0; j < w; j++) tmp[i][pre[j]] = cnt[rson][i][j];
		for (int i = 0; i < w; i++) 
			for (int j = 0; j < w; j++) cnt[rson][i][j] = tmp[i][j];
		tag[lson] += x;
		tag[rson] += x;
		x = 0;
	}
	void shift(int p, int l, int r, int L, int R, int x) {
		if (l >= L && r <= R) {
			int xx = x % w;
			for (int j = 0; j < w; j++) pre[j] = (j + xx + w) % w;
			for (int i = 0; i < w; i++)
				for (int j = 0; j < w; j++) tmp[i][pre[j]] = cnt[p][i][j];
			for (int i = 0; i < w; i++)
				for (int j = 0; j < w; j++) cnt[p][i][j] = tmp[i][j];
			tag[p] += x;
			return;
		}
		pushdown(p);
		if (L <= mid) shift(lson, l, mid, L, R, x);
		if (R > mid) shift(rson, mid + 1, r, L, R, x);
		pushup(p);
	}
	int calc() {
		int res = 0;
		for (int i = 0; i < w; i++) {
			for (int j = 0; j < w; j++) {
				int x = cnt[1][i][j];
				res = (res + i * 1ll * fpow(j, k, w) % w * x % mod) % mod;
			}
		}
		return res;
	}
} T1;
int binom[7][7];
int get(int l, int r, int k) {
	return (sum[r][k] + mod - sum[l - 1][k]) % mod;
}
struct Tree2 {
	int f[N << 2][6], tag[N << 2], tmp[6];
	void pushup(int p) {
		for (int i = 0; i <= k; i++) f[p][i] = (f[lson][i] + f[rson][i]) % mod;
	}
	void build(int p, int l, int r) {
		if (l == r) {
			int ll = qry(l - 1), rr = qry(l);
			if (ll == rr) return;
			++ll;
			for (int i = 0; i <= k; i++) 
				f[p][i] = get(ll, rr, i) * 1ll * l % mod;
			return;
		}
		build(lson, l, mid), build(rson, mid + 1, r);
		pushup(p);
	}
	void pushdown(int p) {
		if (tag[p] == 0) return;
		int &x = tag[p];
		memset(tmp, 0, sizeof tmp);
		for (int i = 0; i <= k; i++) 
			for (int j = 0; j <= i; j++) 
				tmp[i] = (tmp[i] + binom[i][j] * 1ll * fpow(x, i - j, mod) % mod * f[lson][j] % mod) % mod;
		for (int i = 0; i <= k; i++) f[lson][i] = tmp[i];
		memset(tmp, 0, sizeof tmp);
		for (int i = 0; i <= k; i++) 
			for (int j = 0; j <= i; j++) 
				tmp[i] = (tmp[i] + binom[i][j] * 1ll * fpow(x, i - j, mod) % mod * f[rson][j] % mod) % mod;
		for (int i = 0; i <= k; i++) f[rson][i] = tmp[i];
		tag[lson] += x;
		tag[rson] += x;
		x = 0;
	}
	void shift(int p, int l, int r, int L, int R, int x) {
		if (l >= L && r <= R) {
			memset(tmp, 0, sizeof tmp);
			for (int i = 0; i <= k; i++) 
				for (int j = 0; j <= i; j++) 
					tmp[i] = (tmp[i] + binom[i][j] * 1ll * fpow(x, i - j, mod) % mod * f[p][j] % mod) % mod;
			for (int i = 0; i <= k; i++) f[p][i] = tmp[i];
			tag[p] += x;
			return;
		}
		pushdown(p);
		if (L <= mid) shift(lson, l, mid, L, R, x);
		if (R > mid) shift(rson, mid + 1, r, L, R, x);
		pushup(p);
	}
} T2;

void modify(int p, int l, int r, int pos, int tp) {
	if (l == r) {
		if (tp == 1) {
			add(l, 1);
			int x = qry(l);
			T1.cnt[p][l % w][x % w]++;
			for (int i = 0; i <= k; i++) T2.f[p][i] = (T2.f[p][i] + l * 1ll * fpow(x, i, mod) % mod) % mod;
			if (pos != M) T1.shift(1, 0, M, l + 1, M, 1), T2.shift(1, 0, M, l + 1, M, 1);
		} else {
			int x = qry(l);
			add(l, -1);
			T1.cnt[p][l % w][x % w]--;
			for (int i = 0; i <= k; i++) T2.f[p][i] = (T2.f[p][i] + mod - l * 1ll * fpow(x, i, mod) % mod) % mod;
			if (pos != M) T1.shift(1, 0, M, l + 1, M, -1), T2.shift(1, 0, M, l + 1, M, -1);
		}
		return;
	}
	T1.pushdown(p);
	T2.pushdown(p);
	if (pos <= mid) modify(lson, l, mid, pos, tp);
	else modify(rson, mid + 1, r, pos, tp);
	T1.pushup(p);
	T2.pushup(p);
}

void solve() {
	cin >> n >> k >> w;
	//n = 100000, k = w = 5;
	for (int j = 0; j <= 5; j++) {
		sum[0][j] = 1;
		for (int i = 1; i < N; i++) {
			sum[i][j] = (sum[i - 1][j] + fpow(i, j, mod)) % mod;
		}
	}
	for (int i = 0; i < 6; i++) {
		binom[i][0] = binom[i][i] = 1;
		for (int j = 1; j < i; j++) 
			binom[i][j] = (binom[i - 1][j] + binom[i - 1][j - 1]) % mod;
	}
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		//a[i] = rand() % (M + 1);
		add(a[i], 1);
	}
	T1.build(1, 0, M);
	T2.build(1, 0, M);
	cin >> q;
	//q = 100000;
	while (q--) {
		int pos, x;
		cin >> pos >> x;
		//pos = rand() % n + 1, x = rand() % (M + 1);
		modify(1, 0, M, a[pos], -1);
		a[pos] = x;
		modify(1, 0, M, a[pos], 1);
		int ans = (mod - T1.calc() + T2.f[1][k]) % mod;
		ans = ans * 1ll * fpow(w, mod - 2, mod) % mod;
		cout << (ans + mod) % mod << '\n';
	}
}

signed main() {
	srand(time(0));
	ios::sync_with_stdio(0), cin.tie(0);
	int T = 1;
	while (T--) solve();
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 7ms
memory: 54356kb

input:

3 1 1
2 2 8
2
2 5
3 6

output:

36
30

result:

ok 2 number(s): "36 30"

Test #2:

score: 0
Accepted
time: 4ms
memory: 55056kb

input:

4 2 2
1 3 3 7
4
1 1
2 4
3 8
4 8

output:

75
80
103
108

result:

ok 4 number(s): "75 80 103 108"

Test #3:

score: 0
Accepted
time: 9ms
memory: 54964kb

input:

10 1 1
16251 28898 58179 69362 48663 81443 34949 87167 16552 58931
10
6 89124
8 27159
4 7332
1 15852
9 67405
7 19413
10 97472
7 31114
6 31847
5 43794

output:

3511390
3107346
2780002
2779204
3079414
3018965
3365708
3406982
2970195
2936112

result:

ok 10 numbers

Test #4:

score: 0
Accepted
time: 11ms
memory: 57792kb

input:

100 2 2
44625 87890 57662 73552 89172 64466 22834 24089 60132 5187 88984 19022 67559 53954 42114 19018 80035 3367 50518 15479 72359 15452 38886 5945 34974 86214 16805 71388 48981 45377 34170 61384 88881 29453 94738 94669 56746 80508 79155 94505 82745 38134 41769 2032 23186 5636 39727 54400 86133 497...

output:

81216962
152846115
156547587
163221145
293598979
178882623
92185541
202208317
181562234
200670345
213033267
262881364
247600647
301317991
271334928
261885869
261690216
247578015
236998290
291971331
293746018
424418987
402413699
300515771
300819876
344295103
391424353
392633865
361623113
355154190
47...

result:

ok 100 numbers

Test #5:

score: 0
Accepted
time: 23ms
memory: 67144kb

input:

1000 5 5
67444 21858 17070 50937 22108 62205 2999 96284 84111 16255 69173 11611 84406 28349 95817 86160 87289 19642 22706 44359 31899 36187 15946 86429 23120 65928 81187 32204 37790 18497 52182 23455 59579 78480 45277 57706 60123 99315 19014 72404 35420 14632 12210 38628 1729 18606 23941 96652 80784...

output:

448982964
318631979
90368327
811603500
536477662
692557229
62990700
201293231
656272078
39300199
904902483
682330227
415437174
172036954
307435785
263728224
240392540
817310695
279181829
609019128
744046644
313110033
146349180
684606480
105663106
927540631
395442598
940076193
928045549
210861570
871...

result:

ok 1000 numbers

Test #6:

score: 0
Accepted
time: 16ms
memory: 68464kb

input:

1000 4 5
72227 53523 60356 75354 48348 59071 85117 86260 35140 27149 26706 84967 71598 76061 81453 53989 15316 82420 50695 46478 47536 10211 47703 57753 52396 25234 7015 28545 88953 3038 68077 40104 83546 75660 4206 97850 46721 49986 69628 79532 47269 93027 73722 38823 81502 9110 29754 24 19161 1699...

output:

188781625
762228616
136821592
674574163
347192262
485485871
629723820
280908647
588412565
725358221
863705098
659938578
242816623
893332458
843594911
548347865
837091341
189528539
686788524
27959019
161387564
209458902
58082579
541157908
634716980
370997719
711719499
222851922
266533026
468008815
12...

result:

ok 1000 numbers

Test #7:

score: 0
Accepted
time: 15ms
memory: 53696kb

input:

1000 5 5
934 216 913 239 824 359 107 658 672 201 259 787 699 375 495 399 957 273 386 716 148 563 663 746 673 466 938 833 871 307 932 330 175 572 438 641 106 574 148 265 235 48 284 823 142 616 664 401 301 156 36 155 455 46 314 386 80 918 9 283 960 228 576 322 866 871 642 571 93 364 384 343 780 740 29...

output:

863298675
561844282
707253518
131162317
733366001
240959848
491331485
945999426
884095393
601677031
988828395
989129097
271230712
188285368
526283575
610318634
640662356
513566498
530541446
619910493
101188507
650095342
264873841
559625254
219249144
536317513
208763693
184423450
658893967
186389056
...

result:

ok 1000 numbers

Test #8:

score: 0
Accepted
time: 1050ms
memory: 56236kb

input:

100000 5 5
80 589 96 690 525 951 787 896 916 752 55 923 620 300 287 174 450 222 758 283 713 795 782 655 93 795 249 236 692 545 438 356 63 139 441 943 871 187 810 563 634 234 148 160 911 114 487 521 180 416 657 301 35 67 122 338 190 673 630 712 719 216 976 883 51 651 936 531 679 580 804 173 456 815 7...

output:

334846524
735139360
175630055
575968
183966896
545113566
393807292
242141610
253214633
590769329
859345957
37074142
11644872
268286727
70669491
935138232
773027517
769815377
968622436
886520151
263649182
106276038
489295947
665611891
959073798
994348948
331398630
959671469
2420615
919397617
90918278...

result:

ok 100000 numbers

Test #9:

score: 0
Accepted
time: 970ms
memory: 55388kb

input:

100000 5 4
735 435 80 695 784 93 11 865 335 20 38 402 773 258 99 158 444 457 625 882 216 925 98 483 616 528 959 0 52 564 854 511 400 747 889 831 691 854 527 835 513 579 395 761 400 120 244 831 927 679 161 296 736 566 818 682 210 868 931 499 189 288 621 883 748 530 56 809 265 407 590 742 256 487 678 ...

output:

548719996
71520431
568505663
379161284
6097684
102114391
354237340
868665986
14614795
86649147
537310476
422461024
11275154
172576801
425193845
682825227
982196723
672284562
176302530
249023719
594349424
313782752
346527432
52872850
806313812
568528655
609517066
700177790
315782379
352365845
1238981...

result:

ok 100000 numbers

Test #10:

score: 0
Accepted
time: 585ms
memory: 55376kb

input:

100000 2 5
758 521 465 830 421 463 283 166 133 343 524 932 209 754 696 510 884 405 438 529 254 956 708 87 968 3 881 303 530 201 477 8 591 779 976 941 513 777 494 5 650 581 137 524 821 887 972 798 819 161 60 530 267 478 650 473 332 818 564 101 942 139 803 603 465 834 493 103 993 108 439 656 663 354 8...

output:

712639554
393654980
316838492
263825807
136508419
293079232
664358103
882923327
615776339
523830723
175067835
871540343
242950115
425248987
107408844
790371295
846991468
545133566
139624573
717587699
841009747
264863714
127306668
672772119
580191505
135755622
25168918
381363267
803559279
748670082
6...

result:

ok 100000 numbers

Test #11:

score: -100
Wrong Answer
time: 450ms
memory: 101336kb

input:

100000 1 1
98857 95450 8761 8796 32999 3204 79376 59224 19559 86488 68166 79967 76372 45422 83775 69578 58742 16508 54518 83245 5805 23814 18798 8227 61098 48767 97853 33191 19557 69963 29437 93036 23844 57618 30455 47769 22611 35732 15543 8494 53219 98312 11271 8110 18323 25627 57458 52679 39948 98...

output:

615597868
619066366
851553573
926876733
8735834
275036663
438372473
396842684
918474032
170923178
826557182
207028942
540927156
66595495
63352023
121479843
661495623
777646734
265536577
114263069
747959589
722090376
715949374
669058691
508480805
193805020
901175487
351848881
974605864
417308927
6104...

result:

wrong answer 1st numbers differ - expected: '633154338', found: '615597868'