답안 #373223

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
373223 2021-03-03T21:04:00 Z GioChkhaidze Tenis (COI19_tenis) C++14
100 / 100
246 ms 7592 KB
#include <bits/stdc++.h>

#define lf (h << 1)
#define rf ((h << 1) | 1)
#define Tree int h, int l, int r
#define Left lf, l, (l + r) >> 1
#define Right rf, ((l + r) >> 1) + 1, r

using namespace std;

const int N = 1e5 + 5;

int n, q, p, x, A, B, tp;
int M[N], a[N][4], v[4 * N], ad[4 * N];

void Shift(Tree) {
	if (!ad[h]) return ;
	v[lf] += ad[h];
	v[rf] += ad[h];
	ad[lf] += ad[h];
	ad[rf] += ad[h];
	ad[h] = 0;
	return ;	
}

void upd(Tree, int L, int R, int dl) {
	if (r < L || R < l) return ;
	if (L <= l && r <= R) {
		v[h] += dl;
		ad[h] += dl;
		return ; 
	}
	
	Shift(h, l, r);
	upd(Left, L, R, dl);
	upd(Right, L, R, dl);
	v[h] = min(v[lf], v[rf]);
}

int get(Tree) {
	if (l == r) return r;
	Shift(h, l, r);
	if (!v[lf]) 
		return get(Left);
	return get(Right);
}

main () {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	cin >> n >> q;
	for (int j = 0; j < 3; ++j)
		for (int i = 1; i <= n; ++i) {
			cin >> x;
			a[x][j] = i;
			M[x] = max(M[x], i);
		}
	
	for (int i = 1; i <= n; ++i) {
		upd(1, 1, n, i, n, 1);
		upd(1, 1, n, M[i], n, -1);
	}
	
	for (int i = 1; i <= q; ++i) {
		cin >> tp;
		if (tp == 2) {
			cin >> p >> A >> B; --p;
			upd(1, 1, n, M[A], n, 1);
			upd(1, 1, n, M[B], n, 1);

			M[A] = M[B] = 0;
			swap(a[A][p], a[B][p]);
			for (int j = 0; j < 3; ++j) {
				M[A] = max(M[A], a[A][j]);
				M[B] = max(M[B], a[B][j]);
			}

			upd(1, 1, n, M[A], n, -1);
			upd(1, 1, n, M[B], n, -1);
		}
			else
		if (tp == 1) {
			cin >> x;
			if (get(1, 1, n) < M[x]) 
				cout << "NE\n";
					else 
				cout << "DA\n";
		}
	}
}

Compilation message

tenis.cpp:48:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   48 | main () {
      |       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 97 ms 6124 KB Output is correct
14 Correct 103 ms 6144 KB Output is correct
15 Correct 92 ms 6124 KB Output is correct
16 Correct 91 ms 6124 KB Output is correct
17 Correct 98 ms 6124 KB Output is correct
18 Correct 97 ms 6252 KB Output is correct
19 Correct 97 ms 6124 KB Output is correct
20 Correct 113 ms 6124 KB Output is correct
21 Correct 100 ms 6252 KB Output is correct
22 Correct 98 ms 6252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 137 ms 7228 KB Output is correct
2 Correct 137 ms 7276 KB Output is correct
3 Correct 124 ms 7148 KB Output is correct
4 Correct 130 ms 7424 KB Output is correct
5 Correct 129 ms 7148 KB Output is correct
6 Correct 121 ms 7148 KB Output is correct
7 Correct 129 ms 7276 KB Output is correct
8 Correct 127 ms 7148 KB Output is correct
9 Correct 142 ms 7276 KB Output is correct
10 Correct 124 ms 7172 KB Output is correct
11 Correct 122 ms 7276 KB Output is correct
12 Correct 121 ms 7148 KB Output is correct
13 Correct 125 ms 7404 KB Output is correct
14 Correct 125 ms 7276 KB Output is correct
15 Correct 123 ms 7148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 97 ms 6124 KB Output is correct
14 Correct 103 ms 6144 KB Output is correct
15 Correct 92 ms 6124 KB Output is correct
16 Correct 91 ms 6124 KB Output is correct
17 Correct 98 ms 6124 KB Output is correct
18 Correct 97 ms 6252 KB Output is correct
19 Correct 97 ms 6124 KB Output is correct
20 Correct 113 ms 6124 KB Output is correct
21 Correct 100 ms 6252 KB Output is correct
22 Correct 98 ms 6252 KB Output is correct
23 Correct 137 ms 7228 KB Output is correct
24 Correct 137 ms 7276 KB Output is correct
25 Correct 124 ms 7148 KB Output is correct
26 Correct 130 ms 7424 KB Output is correct
27 Correct 129 ms 7148 KB Output is correct
28 Correct 121 ms 7148 KB Output is correct
29 Correct 129 ms 7276 KB Output is correct
30 Correct 127 ms 7148 KB Output is correct
31 Correct 142 ms 7276 KB Output is correct
32 Correct 124 ms 7172 KB Output is correct
33 Correct 122 ms 7276 KB Output is correct
34 Correct 121 ms 7148 KB Output is correct
35 Correct 125 ms 7404 KB Output is correct
36 Correct 125 ms 7276 KB Output is correct
37 Correct 123 ms 7148 KB Output is correct
38 Correct 246 ms 7592 KB Output is correct
39 Correct 147 ms 7276 KB Output is correct
40 Correct 217 ms 7532 KB Output is correct
41 Correct 155 ms 7360 KB Output is correct
42 Correct 169 ms 7532 KB Output is correct
43 Correct 210 ms 7532 KB Output is correct
44 Correct 140 ms 7276 KB Output is correct
45 Correct 167 ms 7404 KB Output is correct
46 Correct 150 ms 7300 KB Output is correct
47 Correct 180 ms 7276 KB Output is correct
48 Correct 146 ms 7276 KB Output is correct
49 Correct 162 ms 7276 KB Output is correct
50 Correct 153 ms 7276 KB Output is correct
51 Correct 160 ms 7276 KB Output is correct
52 Correct 214 ms 7532 KB Output is correct
53 Correct 148 ms 7276 KB Output is correct
54 Correct 154 ms 7276 KB Output is correct
55 Correct 167 ms 7276 KB Output is correct
56 Correct 165 ms 7404 KB Output is correct
57 Correct 153 ms 7276 KB Output is correct
58 Correct 176 ms 7276 KB Output is correct