QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#940242#4346. rpfrdtzlszlt25 1062ms104396kbC++145.7kb2025-03-17 18:13:462025-03-17 18:13:46

Judging History

This is the latest submission verdict.

  • [2025-03-17 18:13:46]
  • Judged
  • Verdict: 25
  • Time: 1062ms
  • Memory: 104396kb
  • [2025-03-17 18:13:46]
  • Submitted

answer

// Problem: P9057 [Ynoi2004] rpfrdtzls
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P9057
// Memory Limit: 512 MB
// Time Limit: 2500 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
#define pb emplace_back
#define fst first
#define scd second
#define mkp make_pair
#define mems(a, x) memset((a), (x), sizeof(a))

using namespace std;
typedef long long ll;
typedef __int128 lll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<ll, ll> pii;

namespace IO {
	const int maxn = 1 << 20;
	
    char ibuf[maxn], *iS, *iT, obuf[maxn], *oS = obuf;

	inline char gc() {
		return (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, maxn, stdin), (iS == iT ? EOF : *iS++) : *iS++);
	}

	template<typename T = int>
	inline T read() {
		char c = gc();
		T x = 0;
		bool f = 0;
		while (c < '0' || c > '9') {
			f |= (c == '-');
			c = gc();
		}
		while (c >= '0' && c <= '9') {
			x = (x << 1) + (x << 3) + (c ^ 48);
			c = gc();
		}
		return f ? ~(x - 1) : x;
	}

	inline void flush() {
		fwrite(obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	
	struct Flusher {
		~Flusher() {
			flush();
		}
	} AutoFlush;

	inline void pc(char ch) {
		if (oS == obuf + maxn) {
			flush();
		}
		*oS++ = ch;
	}

	template<typename T>
	inline void write(T x) {
		static char stk[64], *tp = stk;
		if (x < 0) {
			x = ~(x - 1);
			pc('-');
		}
		do {
			*tp++ = x % 10;
			x /= 10;
		} while (x);
		while (tp != stk) {
			pc((*--tp) | 48);
		}
	}
	
	template<typename T>
	inline void writesp(T x) {
		write(x);
		pc(' ');
	}
	
	template<typename T>
	inline void writeln(T x) {
		write(x);
		pc('\n');
	}
}

using IO::read;
using IO::write;
using IO::pc;
using IO::writesp;
using IO::writeln;

const int maxn = 500100;

ll n, m, K, f[maxn], g[maxn], h[maxn], b[maxn], c[maxn], ans[maxn], nt;
int pre[maxn], nxt[maxn];

struct List1 {
	int nxt[maxn << 1], hd[maxn], len;
	pii to[maxn << 1];
	
	inline void add(int x, pii y) {
		to[++len] = y;
		nxt[len] = hd[x];
		hd[x] = len;
	}
} L1, L2;

struct List2 {
	int to[maxn], nxt[maxn], len, hd[maxn];
	
	inline void add(int x, int y) {
		to[++len] = y;
		nxt[len] = hd[x];
		hd[x] = len;
	}
} L3;

struct que {
	ll op, l, r, x;
} a[maxn];

struct BIT1 {
	ll c[maxn];
	
	inline void update(ll x, ll d) {
		for (int i = x; i <= nt; i += (i & (-i))) {
			c[i] += d;
		}
	}
	
	inline void update(ll l, ll r, ll x) {
		update(l, x);
		update(r + 1, -x);
	}
	
	inline ll query(ll x) {
		ll res = 0;
		for (int i = x; i; i -= (i & (-i))) {
			res += c[i];
		}
		return res;
	}
} T1;

struct BIT2 {
	ll c[maxn];
	
	inline void update(ll x, ll d) {
		for (int i = x; i <= n; i += (i & (-i))) {
			c[i] += d;
		}
	}
	
	inline ll query(ll x) {
		ll res = 0;
		for (int i = x; i; i -= (i & (-i))) {
			res += c[i];
		}
		return res;
	}
	
	inline ll query(ll l, ll r) {
		return query(r) - query(l - 1);
	}
} T2;

inline void update(int i, int k) {
	int t = k, y = 0;
	lll x = b[k];
	while (nxt[t] && x <= K) {
		y += c[t] + 1;
		t = nxt[t];
		x *= b[t];
	}
	f[k] += (i - g[k]) * h[k];
	g[k] = i;
	h[k] = y + 1 - (k == t ? 0 : c[k]);
	for (int p = pre[k]; p && t >= pre[k]; p = pre[p]) {
		x *= b[p];
		y += c[p] + 1;
		while (x / b[t] > K) {
			x /= b[t];
			t = pre[t];
			y -= c[t] + 1;
		}
		f[p] += (i - g[p]) * h[p];
		g[p] = i;
		h[p] = y + 1 - (p == t ? 0 : c[p]);
	}
}

void solve() {
	n = read();
	m = read();
	K = read();
	nt = 1;
	for (int i = 1; i <= m; ++i) {
		a[i].op = read();
		a[i].l = read();
		a[i].r = read();
		if (a[i].op == 1) {
			a[i].x = read();
			L1.add(a[i].l, pii(a[i].x, ++nt));
			L3.add(a[i].r + 1, nt);
		} else {
			L2.add(a[i].l - 1, pii(nt, -i));
			L2.add(a[i].r, pii(nt, i));
		}
	}
	b[nt] = K + 1;
	set<int> S;
	S.insert(0);
	S.insert(nt);
	g[nt] = h[nt] = 1;
	for (int i = 1; i <= n; ++i) {
		for (int _ = L3.hd[i]; _; _ = L3.nxt[_]) {
			int j = L3.to[_];
			j = nt - j + 1;
			if (b[j] == 1) {
				T2.update(j, -1);
				int k = *S.lower_bound(j);
				--c[k];
				update(i, k);
			} else {
				int k = nxt[j];
				T1.update(pre[j] + 1, j, f[j] + (i - g[j]) * h[j]);
				T1.update(j + 1, k, f[k] + (i - g[k]) * h[k]);
				c[k] += c[j];
				f[j] = g[j] = h[j] = f[k] = g[k] = h[k] = b[j] = c[j] = 0;
				if (pre[j]) {
					nxt[pre[j]] = nxt[j];
				}
				if (nxt[j]) {
					pre[nxt[j]] = pre[j];
				}
				S.erase(j);
				update(i, k);
			}
			b[j] = 0;
		}
		for (int _ = L1.hd[i]; _; _ = L1.nxt[_]) {
			pii p = L1.to[_];
			p.scd = nt - p.scd + 1;
			int j = p.scd;
			b[j] = p.fst;
			if (p.fst == 1) {
				T2.update(j, 1);
				int k = *S.lower_bound(j);
				++c[k];
				update(i, k);
			} else {
				auto it = S.insert(j).fst;
				pre[j] = *prev(it);
				nxt[j] = *next(it);
				T1.update(pre[j] + 1, nxt[j], f[nxt[j]] + (i - g[nxt[j]]) * h[nxt[j]]);
				f[nxt[j]] = g[nxt[j]] = h[nxt[j]] = 0;
				nxt[pre[j]] = pre[nxt[j]] = j;
				int k = nxt[j];
				c[j] = T2.query(pre[j] + 1, j);
				c[k] = T2.query(j + 1, k);
				update(i, k);
			}
		}
		for (int _ = L2.hd[i]; _; _ = L2.nxt[_]) {
			pii p = L2.to[_];
			int j = nt - p.fst + 1;
			ll res = T1.query(j);
			int k = *S.lower_bound(j);
			// printf("res: %lld %d %d %lld %lld %lld\n", res, i, k, f[k], g[k], h[k]);
			res += f[k] + (i + 1 - g[k]) * h[k];
			if (p.scd > 0) {
				ans[p.scd] += res;
			} else {
				ans[-p.scd] += -res;
			}
		}
	}
	for (int i = 1; i <= m; ++i) {
		if (a[i].op == 2) {
			writeln(ans[i]);
		}
	}
}

int main() {
	int T = 1;
	// scanf("%d", &T);
	while (T--) {
		solve();
	}
	return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 58992kb

input:

96 96 34
1 32 47 2
1 49 94 9
1 2 65 3
1 16 23 7
1 50 82 10
2 96 96
1 45 45 16
1 41 48 6
2 33 60
1 12 52 7
1 28 28 7
1 14 28 8
1 11 36 7
1 24 58 9
1 65 95 2
2 30 30
1 79 96 863797690
1 52 67 10
1 18 68 1
1 68 73 6
1 33 86 9
1 91 93 49
2 57 69
1 44 86 6
1 93 94 22
1 29 87 1
1 18 60 1
1 47 56 1
1 85 93...

output:

1
83
2
26
86
17
202
119

result:

wrong answer 4th numbers differ - expected: '37', found: '26'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 25
Accepted

Test #21:

score: 25
Accepted
time: 708ms
memory: 104364kb

input:

500000 500000 32
1 398994 486295 6
1 495521 496532 3
1 340319 359823 10
1 450253 453343 272125394
1 181453 287632 7
1 161103 427946 5
1 39180 431029 9
1 38269 459066 2
1 460663 462198 10
1 432981 465351 7
1 400126 404950 786797498
1 324472 411628 10
1 498053 498096 10
1 427482 442429 395990662
1 209...

output:

560397
340227
305445
795778
69006
362702
453306
828479
369281
208468
98128
78906
252771
73134
197775
971946
105447
1041915
142548
167392
108746
170379
641833
402986
50960
32753
220986
63352
70593
306481
790938
166011
593360
850779
524644
46717
297221
81796
1101868
288889
1069
854110
426115
183877
10...

result:

ok 50187 numbers

Test #22:

score: 25
Accepted
time: 717ms
memory: 103364kb

input:

500000 500000 96
1 162409 197608 86491832
1 119401 485466 5
1 469679 469682 49
1 67292 67294 38
1 42525 427048 8
1 24833 42042 7
1 304734 453462 927220523
1 51806 308150 9
1 286883 331903 2
1 59416 105699 3
1 148007 206888 10
1 22526 423440 23280672
1 90058 429103 8
1 255862 471403 2
1 85298 85299 4...

output:

186418
510824
33156
1319124
1691214
264708
23392
398193
11292
308871
854366
1212166
455427
74660
354958
170150
215637
92304
58779
341682
93779
573794
127287
91008
178772
29106
937576
351465
11193
487665
474608
288080
1212486
339597
441154
776945
75895
48822
529106
470736
47612
550063
95895
172816
11...

result:

ok 49916 numbers

Test #23:

score: 25
Accepted
time: 988ms
memory: 103272kb

input:

499998 499997 298841078
1 178930 497400 5
1 282494 321023 7
1 458577 498826 7
1 312654 316797 7
1 318240 483557 5
1 418527 443860 3
2 489382 494250
1 298290 424085 4
1 4873 59978 2
1 53019 110349 2
1 98077 482947 3
1 136634 443522 7
1 16796 403946 9
1 498226 499248 4
2 474970 491963
1 473445 476212 ...

output:

14607
67548
1264080
64364
26077
62688
18130
2233951
3715112
1149014
85611
1028280
1131879
77796
542587
1160499
1121159
3100377
1555207
1265087
176486
373457
117812
202253
1209854
1413344
784864
1442896
4315236
98420
593151
170636
30092
676844
5742
875118
84629
559189
153208
101695
2085632
235299
461...

result:

ok 50122 numbers

Test #24:

score: 25
Accepted
time: 467ms
memory: 89756kb

input:

499997 499999 514131616
2 296448 424410
2 284153 458016
1 340949 417457 2
2 484448 495248
1 4927 251967 2
2 89428 396422
2 359140 440802
2 294291 408314
2 270366 345900
1 66058 111950 6
2 459621 492598
2 432163 445457
2 168206 191946
1 490501 493312 6
2 477415 486540
1 69353 300773 7
1 456857 456860...

output:

127963
173864
10801
525009
139981
181390
80487
32978
13295
47482
9126
217568
399341
3668
313612
135453
689496
74409
430064
846746
238498
158561
27356
94068
349301
328907
193324
1167906
617828
654048
107346
101967
76499
9052
10456
572125
23359
1000876
2102
859743
159747
142342
423955
538941
241981
10...

result:

ok 349779 numbers

Test #25:

score: 25
Accepted
time: 746ms
memory: 101260kb

input:

499998 499997 690372988
1 310395 346740 10
1 487217 490982 3
2 15179 276426
1 21337 172367 9
2 368162 427686
1 205835 486053 2
1 440136 460564 10
1 79805 180777 7
2 198236 207808
2 249570 259646
2 238644 276539
1 126024 154951 8
2 238966 327933
2 168709 387982
1 325584 325584 54
2 400089 424896
1 28...

output:

261248
59525
11547
20154
75792
195475
453496
49616
53346
46575
386229
612291
435957
794948
1004940
483398
101562
836645
6131
255185
448435
246463
388867
2338577
53976
130736
53713
104438
1557716
53124
300488
1076469
41233
171111
329473
303030
219613
56166
295107
703844
1451795
1672379
268037
1336648...

result:

ok 200020 numbers

Test #26:

score: 25
Accepted
time: 1020ms
memory: 101832kb

input:

500000 500000 364164191
1 443500 496779 6
1 270630 270631 36
1 135214 454713 2
1 282793 282793 41
1 134073 134073 9
1 414465 414467 31
1 480966 492850 7
1 478484 490642 10
1 100846 141492 9
1 42361 262039 4
1 405798 496143 2
1 167355 167357 5
1 380818 459413 3
1 360877 360880 8
1 190846 355263 3
2 7...

output:

174433
203487
196409
1171830
1484126
2012445
343657
21465
1734261
745281
2197523
1358480
1867946
765769
81538
255511
1342481
679550
1212701
414541
53070
1512776
1994355
2088675
181669
1140144
1138657
1482332
2314557
202868
951192
187099
237814
757026
508213
3117253
1093855
1548198
28055
3338235
9190...

result:

ok 49923 numbers

Test #27:

score: 25
Accepted
time: 1046ms
memory: 101504kb

input:

500000 499996 827808127
1 235034 382158 2
1 329235 332099 8
1 306681 341990 2
1 25078 287305 3
2 183371 447135
2 48429 286956
1 194930 280532 2
1 274149 374701 10
2 38713 397875
1 374042 432188 4
1 226704 454357 551407746
1 431679 486434 4
1 14987 273852 4
1 196656 366437 857938004
1 108950 296711 1...

output:

553000
528979
979212
933724
561881
37488
802007
1724831
2368869
640664
54450
2434415
704447
1037399
107421
3266581
80938
1604165
1792661
1109140
213249
20710
952084
3196702
1653325
14928
686746
1167464
1788962
3324927
987210
305830
683290
783171
105182
99144
1589517
3316961
70093
1433531
83940
91798...

result:

ok 49649 numbers

Test #28:

score: 25
Accepted
time: 453ms
memory: 92480kb

input:

500000 500000 53926318
2 33002 243201
2 180944 319296
1 251642 282476 6
2 245610 287316
2 453978 456487
1 289598 462517 2
2 222231 456775
2 449953 494978
2 219805 471046
1 257692 443159 6
2 403848 420514
2 225567 338196
1 221045 273088 294474305
2 242143 358481
1 94726 239078 2
2 275561 448674
1 369...

output:

210200
138353
72542
2510
432558
57591
454997
50001
272569
280004
506706
247034
176098
395893
104670
167138
608355
9064
430695
426487
530505
740741
1497937
835547
17880
650067
794931
185930
62888
2023807
500769
1838763
1076285
740322
1312761
103859
2864020
709908
133090
364500
200051
47571
459198
186...

result:

ok 350318 numbers

Test #29:

score: 25
Accepted
time: 1062ms
memory: 104396kb

input:

499995 499998 767955629
1 75749 219940 3
1 180210 271542 6
1 391396 434648 6
1 491640 496304 7
1 440656 454659 3
1 413911 453363 8
1 432846 455313 6
2 307195 370502
1 233245 400380 9
1 246843 492655 2
1 374732 437211 9
1 142423 169154 793560992
1 375902 482181 3
1 320728 320730 27
1 55621 55621 48
1...

output:

63308
31734
7965
574384
204141
64506
418083
94028
115732
160380
931359
339484
441514
48212
569634
128555
1488752
915091
208894
2782678
298522
60444
696851
841030
844161
1753187
1908906
4067756
1558906
42872
189172
203768
577232
63330
1563187
592588
341646
242193
86404
137045
659493
6730
1563938
2903...

result:

ok 49879 numbers

Test #30:

score: 25
Accepted
time: 1062ms
memory: 101332kb

input:

499996 499998 761092880
1 216480 228556 2
1 177632 380437 2
1 105945 334622 856602782
1 275888 369963 7
1 185776 339214 7
2 455528 493977
2 79984 484990
1 335733 335735 24
1 394255 394258 55
1 267103 383323 3
1 27482 27484 58
2 352586 381451
1 335110 351565 8
1 43039 237461 2
1 185760 185763 14
1 30...

output:

38450
698337
102962
6996
843371
415967
821452
871238
998605
722883
562802
549383
78353
426413
2544587
255170
1724080
234169
17516
265053
5178
2566896
680243
420678
337328
930006
47086
307472
28738
1546732
201214
791881
1952570
4149682
14967
2644687
133340
241662
583214
509933
131368
1242581
359368
1...

result:

ok 49985 numbers

Subtask #4:

score: 0
Skipped

Dependency #1:

0%