QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#69019#3554. SweepingQingyu1 21ms20292kbC++233.3kb2022-12-22 16:42:392022-12-22 16:42:41

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-22 16:42:41]
  • Judged
  • Verdict: 1
  • Time: 21ms
  • Memory: 20292kb
  • [2022-12-22 16:42:39]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 50;

int n, m, q, X[N], Y[N], AL[N], AR[N], atot, ans[2][N];
int start[N], rt[4], ch[N << 2][2], mx[N << 2], tot;
vector<pair<int, int>> ops;

int newnode() {
	++tot;
	ch[tot][0] = ch[tot][1] = mx[tot] = 0;
	return tot;
}

void upd(int &o, int l, int r, int ql, int qr, int x) {
	if (ql > qr) return;
	if (!o) {
		o = newnode();
	}
	if (ql <= l && r <= qr) {
		mx[o] = max(mx[o], x);
	}
	else {
		const int mid = l + r >> 1;
		if (ql <= mid) {
			upd(ch[o][0], l, mid, ql, qr, x);
		}
		if (qr > mid) {
			upd(ch[o][1], mid + 1, r, ql, qr, x);
		}
	}
}

int query(int &o, int l, int r, int x) {
	if (!o)
		return 0;
	if (l == r)
		return mx[o];
	const int mid = l + r >> 1;
	if (x <= mid)
		return max(mx[o], query(ch[o][0], l, mid, x));
	else
		return max(mx[o], query(ch[o][1], mid + 1, r, x));
}

int main() {
	cin >> n >> m >> q;
	memset(start, -1, sizeof start);
	for (int i = 1; i <= m; ++i) {
		cin >> X[i] >> Y[i];
		start[i] = 0;
	}
	for (int _ = 1; _ <= q; ++_) {
		int op;
		cin >> op;
		if (op == 1) {
			int p;
			cin >> p;
			++atot;
			ans[0][atot] = X[p];
			ans[1][atot] = Y[p];
			assert(start[p] >= 0);
			AL[atot] = start[p];
			AR[atot] = (int)(ops.size()) - 1;
		}
		else if (op == 2) {
			int p;
			cin >> p;
			ops.emplace_back(p, 0);
		}
		else if (op == 3) {
			int p;
			cin >> p;
			ops.emplace_back(p, 1);
		}
		else if (op == 4) {
			++m;
			int x, y;
			cin >> x >> y;
			X[m] = x, Y[m] = y;
			start[m] = ops.size();
		}
		else throw;
	}
	vector<int> qq;
	for (int i = 1; i <= atot; ++i) {
		int l = AL[i], r = AR[i];
		if (l <= r) {
			qq.push_back(i);
		}
	}
	function<void(int, int, const vector<int>&)> solve = [&](int l, int r, const vector<int> &qq) {
		if (qq.empty())
			return;
		rt[0] = rt[1] = rt[2] = rt[3] = tot = 0;
		const int mid = l + r >> 1;
		vector<int> qql, qqr, qq_cur;
		array<vector<pair<int, int>>, 2> qu;
		for (int i = l; i <= r; ++i) {
			auto [x, op] = ops[i];
			int ql = query(rt[!op], 0, n, x), qr = n - x - 1;
			qu[op].emplace_back(x, ql);
			upd(rt[op], 0, n, ql, qr, x + 1);
		}
		for (auto x : qq) {
			int wl = AL[x], wr = AR[x];
			//printf("wl = %d, wr = %d, l = %d, r = %d\n", wl, wr, l, r);
			if (wl <= l && r <= wr) {
				qq_cur.push_back(x);
			}
			else {
				if (wl <= mid) {
					qql.push_back(x);
				}
				if (wr > mid) {
					qqr.push_back(x);
				}
			}
		}
		for (int o : {0, 1}) {
			sort(qu[o].begin(), qu[o].end(), greater<pair<int, int>>());
			sort(qq_cur.begin(), qq_cur.end(), [&](const int &x, const int &y) {
				return ans[!o][x] > ans[!o][y];
			});
			int pl = 0, pr = 0;
			const auto &f = qu[o];
			while (pl < qq_cur.size()) {
				int x = qq_cur.at(pl);
				while (pr < f.size() && f[pr].first >= ans[!o][x]) {
					int l = f[pr].second, r = n - f[pr].first, v = r;
					upd(rt[o + 2], 0, n, l, r, v);
					++pr;
				}
				int ww = query(rt[o + 2], 0, n, ans[o][x]);
				ans[o][x] = max(ans[o][x], ww);
				++pl;
			}
		}
		solve(l, mid, qql);
		solve(mid + 1, r, qqr);
	};
	solve(0, (int)(ops.size()) - 1, qq);
	for (int i = 1; i <= atot; ++i) {
		cout << ans[0][i] << " " << ans[1][i] << '\n';
	}
	return 0;
}

詳細信息

Subtask #1:

score: 1
Accepted

Test #1:

score: 1
Accepted
time: 16ms
memory: 20088kb

input:

999999999 2000 5000
406191928 499382196
562579162 405324970
758918451 226610082
56425557 481714604
280111172 204083332
178122667 423322594
656895843 125933171
283229448 255332800
375268656 368221716
287124150 218833686
67804037 252992256
736660159 61831334
50624783 762562411
127286172 739867871
2174...

output:

703152954 155393653
568874648 274309686
58956946 596540151
199070534 583395188
373137208 583395188
196862582 704927063
601883225 329807019
487677860 204843014
661256159 204843014
751624518 204843014
174003214 771291775
770471768 204843014
256547879 588907149
36478325 753856112
175794127 588907149
25...

result:

ok 3000 lines

Test #2:

score: 0
Accepted
time: 21ms
memory: 20220kb

input:

934679943 1 5000
2451044 877564810
1 1
1 1
1 1
1 1
1 1
4 120526175 461368727
1 1
1 2
3 450149653
3 620864342
2 178195071
1 1
1 2
1 2
3 413010769
1 2
1 2
1 2
1 2
1 1
2 725221136
3 691448934
3 276663052
1 1
3 930831455
2 815181543
2 623177099
1 2
2 514825170
1 2
3 747856152
1 2
3 402313938
1 2
1 2
1 2...

output:

2451044 877564810
2451044 877564810
2451044 877564810
2451044 877564810
2451044 877564810
2451044 877564810
120526175 461368727
2451044 877564810
120526175 484530290
120526175 484530290
120526175 521669174
120526175 521669174
120526175 521669174
120526175 521669174
2451044 877564810
2451044 87756481...

result:

ok 2000 lines

Test #3:

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

input:

100000 2000 5000
7526 88439
27401 63901
12729 57375
7120 72877
13512 2075
63897 853
48090 291
14049 18666
13887 6324
29293 66392
63465 35961
5818 729
41156 41788
24104 9048
33182 48553
41643 25780
21307 73381
70083 14433
20961 67607
14310 9978
14691 66057
4472 52530
3793 56759
36778 43936
42952 2182...

output:

93757 472
20480 20908
19267 965
69833 3419
2080 69210
50573 5524
33156 62304
979 6058
26908 25623
45999 13768
1611 67556
2076 47375
74817 8082
60023 12927
47630 11842
2799 23736
35387 35461
63486 32454
17971 48983
71368 14571
11521 30462
51725 1593
4801 43324
57759 37197
68055 24129
9335 11578
28609...

result:

ok 3000 lines

Test #4:

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

input:

999999999 2000 5000
161017248 661816587
34004022 23234313
167965869 281976276
897332334 75451535
521734377 459277821
89319285 274155963
7810048 145112921
202825722 342388216
242154981 482232628
850785489 144032676
43212548 298867158
253938084 744483975
66502485 127590206
158762756 836362255
12130099...

output:

79309319 843021393
84078446 218046012
46602912 73317765
688166434 230438453
693577528 227505921
877096026 121090158
2384244 403987102
805467019 42832725
805467019 59328339
176218947 231322193
130728116 858765896
805467019 67531081
805467019 69661485
7620868 854712465
805467019 148331884
176570528 56...

result:

ok 3000 lines

Test #5:

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

input:

1000 2000 5000
388 534
319 136
436 511
698 95
680 155
243 753
63 237
680 265
352 377
14 25
584 86
359 471
14 954
657 98
508 229
159 123
571 296
397 52
224 213
323 76
94 188
263 254
22 81
61 160
527 92
136 60
311 145
410 390
713 262
348 595
883 58
268 491
208 746
245 269
135 862
537 175
318 223
361 1...

output:

381 619

result:

ok single line: '381 619'

Test #6:

score: 0
Accepted
time: 3ms
memory: 19900kb

input:

1 2000 5000
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
...

output:

1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
1 0
...

result:

ok 3000 lines

Subtask #2:

score: 0
Runtime Error

Test #7:

score: 0
Runtime Error

input:

1000000000 500000 1000000
565671866 434313351
151160620 848839277
759673958 240326022
747919325 251939968
652216454 341792707
697972826 302025968
437943290 562056699
963595717 25130832
833492450 163447023
453783218 546216655
852488265 147511733
364464144 334147914
493873353 504061372
104992045 86556...

output:


result:


Subtask #3:

score: 0
Memory Limit Exceeded

Test #14:

score: 0
Memory Limit Exceeded

input:

1000000000 499999 1000000
1603 999995752
1621 999984188
3408 999983654
3743 999979285
3830 999978594
5050 999974201
7426 999970241
13957 999962424
14611 999962335
16341 999954169
20684 999953545
21401 999952737
25492 999948443
25736 999946928
26128 999941492
29341 999937495
29753 999929827
33929 999...

output:


result:


Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%