Submission #234791

# Submission time Handle Problem Language Result Execution time Memory
234791 2020-05-25T15:44:29 Z Atalasion Tenis (COI19_tenis) C++14
100 / 100
282 ms 8060 KB
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize ("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-O2")


using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 100000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000010;
const ll LOG = 25;

int n, q, P[3][N], koj[3][N], seg[N << 2], lazy[N << 2];

void modify(int id, int x){
	seg[id] += x;
	lazy[id] += x;
}

void shift(int id){
	modify(id << 1, lazy[id]);
	modify(id << 1 | 1, lazy[id]);
	lazy[id] = 0;
}

void add(int id, int lq, int rq, int x, int l, int r){
	if (rq <= l || r <= lq) return;
	if (lq <= l && r <= rq){
		modify(id, x);
		return;
	}
	int md = (l + r) >> 1;
	shift(id);
	add(id << 1, lq, rq, x,l ,md);
	add(id << 1 | 1, lq, rq, x, md, r);
	seg[id] = min(seg[id << 1], seg[id << 1 | 1]);
}

int get(int id, int l, int r){
	if (r - l == 1) return l;
	shift(id);
	int md = (l + r )>> 1;
	if (seg[id << 1] == 0) return get(id << 1, l, md);
	return get(id << 1 | 1, md, r);
}

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> q;
	for (int i = 0; i < 3; i++){
		for (int j = 1; j <= n; j++){
			cin >> P[i][j];
			koj[i][P[i][j]] = j;
		}
	}
	for (int i = 1; i <= n; i++){
		add(1, min({koj[0][i], koj[1][i], koj[2][i]}), n + 1, 1, 1, n + 1);
		add(1, max({koj[0][i], koj[1][i], koj[2][i]}), n + 1, -1, 1, n + 1);
	}
	for (int i = 1; i <= q; i++){
		int x;
		cin >> x;
		if (x == 1){
			int c;
			cin >> c;
			int K = get(1, 1, n + 1);
//			cout << K << '\n';
			if (K >= koj[0][c]) cout << "DA\n";
			else cout << "NE\n";
		}else{
			int p, a, b;
			cin >> p >> a >> b;
			p--;
			int x = koj[p][a], y = koj[p][b];
			add(1, min({koj[0][a], koj[1][a], koj[2][a]}), n + 1, -1, 1, n + 1);
			add(1, max({koj[0][a], koj[1][a], koj[2][a]}), n + 1, 1, 1, n + 1);
			add(1, min({koj[0][b], koj[1][b], koj[2][b]}), n + 1, -1, 1, n + 1);
			add(1, max({koj[0][b], koj[1][b], koj[2][b]}), n + 1, 1, 1, n + 1);
			koj[p][a] = y, koj[p][b] = x;
			add(1, min({koj[0][a], koj[1][a], koj[2][a]}), n + 1, +1, 1, n + 1);
			add(1, max({koj[0][a], koj[1][a], koj[2][a]}), n + 1, -1, 1, n + 1);
			add(1, min({koj[0][b], koj[1][b], koj[2][b]}), n + 1, +1, 1, n + 1);
			add(1, max({koj[0][b], koj[1][b], koj[2][b]}), n + 1, -1, 1, n + 1);
		}
	}










	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 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 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 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 384 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 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 384 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 92 ms 6392 KB Output is correct
14 Correct 123 ms 6520 KB Output is correct
15 Correct 97 ms 6400 KB Output is correct
16 Correct 106 ms 6504 KB Output is correct
17 Correct 93 ms 6392 KB Output is correct
18 Correct 93 ms 6524 KB Output is correct
19 Correct 90 ms 6520 KB Output is correct
20 Correct 92 ms 6392 KB Output is correct
21 Correct 95 ms 6392 KB Output is correct
22 Correct 106 ms 6392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 145 ms 5112 KB Output is correct
2 Correct 139 ms 7544 KB Output is correct
3 Correct 134 ms 7544 KB Output is correct
4 Correct 157 ms 7672 KB Output is correct
5 Correct 144 ms 7648 KB Output is correct
6 Correct 155 ms 7624 KB Output is correct
7 Correct 121 ms 7544 KB Output is correct
8 Correct 145 ms 7544 KB Output is correct
9 Correct 129 ms 7544 KB Output is correct
10 Correct 124 ms 7544 KB Output is correct
11 Correct 132 ms 7544 KB Output is correct
12 Correct 129 ms 7544 KB Output is correct
13 Correct 131 ms 7596 KB Output is correct
14 Correct 129 ms 7544 KB Output is correct
15 Correct 127 ms 7544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 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 384 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 92 ms 6392 KB Output is correct
14 Correct 123 ms 6520 KB Output is correct
15 Correct 97 ms 6400 KB Output is correct
16 Correct 106 ms 6504 KB Output is correct
17 Correct 93 ms 6392 KB Output is correct
18 Correct 93 ms 6524 KB Output is correct
19 Correct 90 ms 6520 KB Output is correct
20 Correct 92 ms 6392 KB Output is correct
21 Correct 95 ms 6392 KB Output is correct
22 Correct 106 ms 6392 KB Output is correct
23 Correct 145 ms 5112 KB Output is correct
24 Correct 139 ms 7544 KB Output is correct
25 Correct 134 ms 7544 KB Output is correct
26 Correct 157 ms 7672 KB Output is correct
27 Correct 144 ms 7648 KB Output is correct
28 Correct 155 ms 7624 KB Output is correct
29 Correct 121 ms 7544 KB Output is correct
30 Correct 145 ms 7544 KB Output is correct
31 Correct 129 ms 7544 KB Output is correct
32 Correct 124 ms 7544 KB Output is correct
33 Correct 132 ms 7544 KB Output is correct
34 Correct 129 ms 7544 KB Output is correct
35 Correct 131 ms 7596 KB Output is correct
36 Correct 129 ms 7544 KB Output is correct
37 Correct 127 ms 7544 KB Output is correct
38 Correct 263 ms 7800 KB Output is correct
39 Correct 171 ms 7548 KB Output is correct
40 Correct 282 ms 8060 KB Output is correct
41 Correct 182 ms 7672 KB Output is correct
42 Correct 192 ms 7800 KB Output is correct
43 Correct 271 ms 7800 KB Output is correct
44 Correct 161 ms 7672 KB Output is correct
45 Correct 207 ms 7672 KB Output is correct
46 Correct 171 ms 7800 KB Output is correct
47 Correct 195 ms 7672 KB Output is correct
48 Correct 171 ms 7544 KB Output is correct
49 Correct 209 ms 7672 KB Output is correct
50 Correct 182 ms 7672 KB Output is correct
51 Correct 203 ms 7928 KB Output is correct
52 Correct 280 ms 7800 KB Output is correct
53 Correct 175 ms 7672 KB Output is correct
54 Correct 193 ms 7800 KB Output is correct
55 Correct 189 ms 7800 KB Output is correct
56 Correct 203 ms 7672 KB Output is correct
57 Correct 171 ms 7800 KB Output is correct
58 Correct 202 ms 7672 KB Output is correct