Submission #994992

# Submission time Handle Problem Language Result Execution time Memory
994992 2024-06-08T09:29:46 Z vjudge1 Tenis (COI19_tenis) C++17
100 / 100
273 ms 7764 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MAXN = 1e5 + 100;
int rv[3][MAXN];
int sg[4*MAXN], lazy[4*MAXN];
void init(int k, int a, int b) {
	if (a == b) {
		sg[k] = a;
		return ;
	}
	init(2*k, a, (a+b)/2);
	init(2*k+1, (a+b)/2+1, b);
	sg[k] = min(sg[2*k], sg[2*k+1]);
}

void push(int k, int a, int b) {
	sg[k] += lazy[k];
	if (a != b) {
		lazy[2*k] += lazy[k];
		lazy[2*k+1] += lazy[k];
	}
	lazy[k] = 0;
}

void update(int k, int a, int b, int q_l, int q_r, int val) {
	push(k, a, b);
	if (q_r < a || q_l > b)
		return ;
	if (q_l <= a && b <= q_r) {
		lazy[k] += val;
		push(k, a, b);
		return ;
	}
	update(2*k, a, (a+b)/2, q_l, q_r, val);
	update(2*k+1, (a+b)/2+1, b, q_l, q_r, val);
	sg[k] = min(sg[2*k], sg[2*k+1]);
}

int query(int k, int a, int b) {
	push(k, a, b);
	if (a == b) {
		return a;
	}
	push(2*k, a, (a+b)/2);
	push(2*k+1, (a+b)/2+1, b);
	if (sg[2*k] == 0)
		return query(2*k, a, (a+b)/2);
	return query(2*k+1, (a+b)/2+1, b);
}

int maxi(int x, int y, int z) {
	return max(x, max(y, z));
}

int main() {
	int N, Q;
	cin >> N >> Q;

	for (int i = 1; i <= N; i++) {
		int x; cin >> x;
		rv[0][x] = i;
	}
	for (int i = 1; i <= N; i++) {
		int x; cin >> x;
		rv[1][x] = i;
	}
	for (int i = 1; i <= N; i++) {
		int x; cin >> x;
		rv[2][x] = i;
	}
	init(1, 1, N);

	for (int i = 1; i <= N; i++)
		update(1, 1, N, maxi(rv[0][i], rv[1][i], rv[2][i]), N, -1);
	while (Q--) {
		int type;
		cin >> type;
		if (type == 1) {
			int x; cin >> x;
			if (maxi(rv[0][x], rv[1][x], rv[2][x]) <= query(1, 1, N))
				cout << "DA" << "\n";
			else
				cout << "NE" << "\n";
		} else {
			int p, a, b;
			cin >> p >> a >> b;
			update(1, 1, N, maxi(rv[0][a], rv[1][a], rv[2][a]), N, 1);
			update(1, 1, N, maxi(rv[0][b], rv[1][b], rv[2][b]), N, 1);
			swap(rv[p-1][a], rv[p-1][b]);
			update(1, 1, N, maxi(rv[0][a], rv[1][a], rv[2][a]), N, -1);
			update(1, 1, N, maxi(rv[0][b], rv[1][b], rv[2][b]), N, -1);
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 4696 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4552 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 4696 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4552 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
13 Correct 88 ms 6264 KB Output is correct
14 Correct 68 ms 6224 KB Output is correct
15 Correct 70 ms 6224 KB Output is correct
16 Correct 68 ms 6228 KB Output is correct
17 Correct 81 ms 6436 KB Output is correct
18 Correct 105 ms 6228 KB Output is correct
19 Correct 68 ms 6228 KB Output is correct
20 Correct 67 ms 6228 KB Output is correct
21 Correct 82 ms 6228 KB Output is correct
22 Correct 105 ms 6228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 218 ms 7448 KB Output is correct
2 Correct 213 ms 7504 KB Output is correct
3 Correct 214 ms 7504 KB Output is correct
4 Correct 215 ms 7508 KB Output is correct
5 Correct 257 ms 7332 KB Output is correct
6 Correct 230 ms 7508 KB Output is correct
7 Correct 212 ms 7468 KB Output is correct
8 Correct 216 ms 7396 KB Output is correct
9 Correct 215 ms 7504 KB Output is correct
10 Correct 273 ms 7468 KB Output is correct
11 Correct 232 ms 7508 KB Output is correct
12 Correct 215 ms 7252 KB Output is correct
13 Correct 216 ms 7504 KB Output is correct
14 Correct 270 ms 7508 KB Output is correct
15 Correct 220 ms 7468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 4696 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4552 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
13 Correct 88 ms 6264 KB Output is correct
14 Correct 68 ms 6224 KB Output is correct
15 Correct 70 ms 6224 KB Output is correct
16 Correct 68 ms 6228 KB Output is correct
17 Correct 81 ms 6436 KB Output is correct
18 Correct 105 ms 6228 KB Output is correct
19 Correct 68 ms 6228 KB Output is correct
20 Correct 67 ms 6228 KB Output is correct
21 Correct 82 ms 6228 KB Output is correct
22 Correct 105 ms 6228 KB Output is correct
23 Correct 218 ms 7448 KB Output is correct
24 Correct 213 ms 7504 KB Output is correct
25 Correct 214 ms 7504 KB Output is correct
26 Correct 215 ms 7508 KB Output is correct
27 Correct 257 ms 7332 KB Output is correct
28 Correct 230 ms 7508 KB Output is correct
29 Correct 212 ms 7468 KB Output is correct
30 Correct 216 ms 7396 KB Output is correct
31 Correct 215 ms 7504 KB Output is correct
32 Correct 273 ms 7468 KB Output is correct
33 Correct 232 ms 7508 KB Output is correct
34 Correct 215 ms 7252 KB Output is correct
35 Correct 216 ms 7504 KB Output is correct
36 Correct 270 ms 7508 KB Output is correct
37 Correct 220 ms 7468 KB Output is correct
38 Correct 224 ms 7764 KB Output is correct
39 Correct 232 ms 7460 KB Output is correct
40 Correct 204 ms 7716 KB Output is correct
41 Correct 228 ms 7472 KB Output is correct
42 Correct 209 ms 7508 KB Output is correct
43 Correct 201 ms 7760 KB Output is correct
44 Correct 217 ms 7472 KB Output is correct
45 Correct 200 ms 7508 KB Output is correct
46 Correct 220 ms 7400 KB Output is correct
47 Correct 246 ms 7508 KB Output is correct
48 Correct 215 ms 7588 KB Output is correct
49 Correct 206 ms 7472 KB Output is correct
50 Correct 213 ms 7508 KB Output is correct
51 Correct 215 ms 7660 KB Output is correct
52 Correct 204 ms 7760 KB Output is correct
53 Correct 261 ms 7512 KB Output is correct
54 Correct 242 ms 7504 KB Output is correct
55 Correct 210 ms 7504 KB Output is correct
56 Correct 210 ms 7648 KB Output is correct
57 Correct 249 ms 7392 KB Output is correct
58 Correct 217 ms 7504 KB Output is correct