Submission #234572

# Submission time Handle Problem Language Result Execution time Memory
234572 2020-05-24T16:08:58 Z pedy4000 Tenis (COI19_tenis) C++14
100 / 100
292 ms 7800 KB
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

const int N = 1e5 + 5;
int n, q;
int rann[N][3];
int mn[N << 2];
int lf[N << 2];
int lazy[N << 2];

int getRankMin (int v) {
	return min({rann[v][0], rann[v][1], rann[v][2]});
}

int getRankMax (int v) {
	return max({rann[v][0], rann[v][1], rann[v][2]});
}

void build (int s = 0, int e = n + 1, int id = 1) {
	lf[id] = s;
	if (e - s == 1)
		return ;

	int mid = e + s >> 1;
	build(s, mid, id << 1);
	build(mid, e, id << 1 | 1);
}

void shift (int id) {
	mn[id << 1] += lazy[id];
	lazy[id << 1] += lazy[id];

	mn[id << 1 | 1] += lazy[id];
	lazy[id << 1 | 1] += lazy[id];
	
	lazy[id] = 0;
}

void add (int val, int l, int r, int s = 0, int e = n + 1, int id = 1) {
	if (l <= s && e <= r) {
		mn[id] += val;
		lazy[id] += val;
		return ;
	}
	if (r <= s || e <= l)
		return ;

	if (lazy[id])
		shift(id);

	int mid = e + s >> 1;
	add(val, l, r, s, mid, id << 1);
	add(val, l, r, mid, e, id << 1 | 1);
	mn[id] = min(mn[id << 1], mn[id << 1 | 1]);
	lf[id] = lf[id << 1 | 1];
	if (mn[id] == mn[id << 1])
		lf[id] = lf[id << 1];
}

int main() {
	ios::sync_with_stdio(false), cin.tie();
	cin >> n >> q;
	for (int t = 0; t < 3; t++)
		for (int i = 0; i < n; i++) {
			int val;
			cin >> val;
			rann[--val][t] = i;
		}

	build();
	for (int i = 0; i < n; i++)
		if (getRankMin(i) != getRankMax(i))
			add(+1, getRankMin(i), getRankMax(i));
	
	while (q--) {
		int type;
		cin >> type;

		if (type == 1) {
			int x;
			cin >> x;

			if (rann[--x][0] <= lf[1])
				cout << "DA\n";
			else
				cout << "NE\n";
		}
		else {
			int p, a, b;
			cin >> p >> a >> b;
			p--, a--, b--;

			if (getRankMin(a) != getRankMax(a))
				add(-1, getRankMin(a), getRankMax(a));
			if (getRankMin(b) != getRankMax(b))
				add(-1, getRankMin(b), getRankMax(b));
			swap(rann[a][p], rann[b][p]);
			if (getRankMin(a) != getRankMax(a))
				add(+1, getRankMin(a), getRankMax(a));
			if (getRankMin(b) != getRankMax(b))
				add(+1, getRankMin(b), getRankMax(b));
		}
	}
	return 0;
}

Compilation message

tenis.cpp: In function 'void build(int, int, int)':
tenis.cpp:26:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid = e + s >> 1;
            ~~^~~
tenis.cpp: In function 'void add(int, int, int, int, int, int)':
tenis.cpp:53:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid = e + s >> 1;
            ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 6 ms 408 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 6 ms 408 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 78 ms 6392 KB Output is correct
14 Correct 84 ms 6264 KB Output is correct
15 Correct 88 ms 6264 KB Output is correct
16 Correct 81 ms 6392 KB Output is correct
17 Correct 69 ms 6264 KB Output is correct
18 Correct 67 ms 6392 KB Output is correct
19 Correct 67 ms 6264 KB Output is correct
20 Correct 88 ms 6392 KB Output is correct
21 Correct 67 ms 6400 KB Output is correct
22 Correct 75 ms 6272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 291 ms 4856 KB Output is correct
2 Correct 285 ms 7488 KB Output is correct
3 Correct 279 ms 7416 KB Output is correct
4 Correct 267 ms 7416 KB Output is correct
5 Correct 274 ms 7416 KB Output is correct
6 Correct 266 ms 7416 KB Output is correct
7 Correct 289 ms 7416 KB Output is correct
8 Correct 286 ms 7288 KB Output is correct
9 Correct 284 ms 7416 KB Output is correct
10 Correct 281 ms 7416 KB Output is correct
11 Correct 292 ms 7464 KB Output is correct
12 Correct 279 ms 7544 KB Output is correct
13 Correct 275 ms 7420 KB Output is correct
14 Correct 282 ms 7416 KB Output is correct
15 Correct 273 ms 7416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 6 ms 408 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 78 ms 6392 KB Output is correct
14 Correct 84 ms 6264 KB Output is correct
15 Correct 88 ms 6264 KB Output is correct
16 Correct 81 ms 6392 KB Output is correct
17 Correct 69 ms 6264 KB Output is correct
18 Correct 67 ms 6392 KB Output is correct
19 Correct 67 ms 6264 KB Output is correct
20 Correct 88 ms 6392 KB Output is correct
21 Correct 67 ms 6400 KB Output is correct
22 Correct 75 ms 6272 KB Output is correct
23 Correct 291 ms 4856 KB Output is correct
24 Correct 285 ms 7488 KB Output is correct
25 Correct 279 ms 7416 KB Output is correct
26 Correct 267 ms 7416 KB Output is correct
27 Correct 274 ms 7416 KB Output is correct
28 Correct 266 ms 7416 KB Output is correct
29 Correct 289 ms 7416 KB Output is correct
30 Correct 286 ms 7288 KB Output is correct
31 Correct 284 ms 7416 KB Output is correct
32 Correct 281 ms 7416 KB Output is correct
33 Correct 292 ms 7464 KB Output is correct
34 Correct 279 ms 7544 KB Output is correct
35 Correct 275 ms 7420 KB Output is correct
36 Correct 282 ms 7416 KB Output is correct
37 Correct 273 ms 7416 KB Output is correct
38 Correct 283 ms 7672 KB Output is correct
39 Correct 259 ms 7672 KB Output is correct
40 Correct 290 ms 7800 KB Output is correct
41 Correct 255 ms 7672 KB Output is correct
42 Correct 248 ms 7544 KB Output is correct
43 Correct 285 ms 7672 KB Output is correct
44 Correct 266 ms 7416 KB Output is correct
45 Correct 256 ms 7672 KB Output is correct
46 Correct 260 ms 7544 KB Output is correct
47 Correct 258 ms 7544 KB Output is correct
48 Correct 279 ms 7436 KB Output is correct
49 Correct 266 ms 7544 KB Output is correct
50 Correct 267 ms 7416 KB Output is correct
51 Correct 271 ms 7548 KB Output is correct
52 Correct 281 ms 7672 KB Output is correct
53 Correct 270 ms 7544 KB Output is correct
54 Correct 253 ms 7672 KB Output is correct
55 Correct 263 ms 7544 KB Output is correct
56 Correct 254 ms 7544 KB Output is correct
57 Correct 265 ms 7544 KB Output is correct
58 Correct 283 ms 7672 KB Output is correct