답안 #868971

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
868971 2023-11-02T16:44:09 Z serifefedartar Tenis (COI19_tenis) C++17
100 / 100
152 ms 7764 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9+7;
const ll LOGN = 30; 
const ll MAXN = 1e5 + 100;
const ll MULT = 1e9;

int rankV[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() {
	fast
	int N, Q;
	cin >> N >> Q;

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

	for (int i = 1; i <= N; i++)
		update(1, 1, N, maxi(rankV[0][i], rankV[1][i], rankV[2][i]), N, -1);
	while (Q--) {
		int type;
		cin >> type;
		if (type == 1) {
			int x; cin >> x;
			if (maxi(rankV[0][x], rankV[1][x], rankV[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(rankV[0][a], rankV[1][a], rankV[2][a]), N, 1);
			update(1, 1, N, maxi(rankV[0][b], rankV[1][b], rankV[2][b]), N, 1);
			swap(rankV[p-1][a], rankV[p-1][b]);
			update(1, 1, N, maxi(rankV[0][a], rankV[1][a], rankV[2][a]), N, -1);
			update(1, 1, N, maxi(rankV[0][b], rankV[1][b], rankV[2][b]), N, -1);
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 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 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 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 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 45 ms 6464 KB Output is correct
14 Correct 43 ms 6492 KB Output is correct
15 Correct 44 ms 6744 KB Output is correct
16 Correct 42 ms 6236 KB Output is correct
17 Correct 40 ms 6224 KB Output is correct
18 Correct 41 ms 6492 KB Output is correct
19 Correct 42 ms 6236 KB Output is correct
20 Correct 44 ms 6228 KB Output is correct
21 Correct 45 ms 6484 KB Output is correct
22 Correct 56 ms 6444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 4924 KB Output is correct
2 Correct 83 ms 7508 KB Output is correct
3 Correct 69 ms 7504 KB Output is correct
4 Correct 73 ms 7484 KB Output is correct
5 Correct 68 ms 7388 KB Output is correct
6 Correct 74 ms 7500 KB Output is correct
7 Correct 70 ms 7508 KB Output is correct
8 Correct 71 ms 7504 KB Output is correct
9 Correct 70 ms 7508 KB Output is correct
10 Correct 68 ms 7368 KB Output is correct
11 Correct 72 ms 7512 KB Output is correct
12 Correct 70 ms 7508 KB Output is correct
13 Correct 73 ms 7548 KB Output is correct
14 Correct 88 ms 7436 KB Output is correct
15 Correct 69 ms 7420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 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 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 45 ms 6464 KB Output is correct
14 Correct 43 ms 6492 KB Output is correct
15 Correct 44 ms 6744 KB Output is correct
16 Correct 42 ms 6236 KB Output is correct
17 Correct 40 ms 6224 KB Output is correct
18 Correct 41 ms 6492 KB Output is correct
19 Correct 42 ms 6236 KB Output is correct
20 Correct 44 ms 6228 KB Output is correct
21 Correct 45 ms 6484 KB Output is correct
22 Correct 56 ms 6444 KB Output is correct
23 Correct 68 ms 4924 KB Output is correct
24 Correct 83 ms 7508 KB Output is correct
25 Correct 69 ms 7504 KB Output is correct
26 Correct 73 ms 7484 KB Output is correct
27 Correct 68 ms 7388 KB Output is correct
28 Correct 74 ms 7500 KB Output is correct
29 Correct 70 ms 7508 KB Output is correct
30 Correct 71 ms 7504 KB Output is correct
31 Correct 70 ms 7508 KB Output is correct
32 Correct 68 ms 7368 KB Output is correct
33 Correct 72 ms 7512 KB Output is correct
34 Correct 70 ms 7508 KB Output is correct
35 Correct 73 ms 7548 KB Output is correct
36 Correct 88 ms 7436 KB Output is correct
37 Correct 69 ms 7420 KB Output is correct
38 Correct 128 ms 7760 KB Output is correct
39 Correct 83 ms 7488 KB Output is correct
40 Correct 121 ms 7760 KB Output is correct
41 Correct 94 ms 7508 KB Output is correct
42 Correct 96 ms 7732 KB Output is correct
43 Correct 152 ms 7584 KB Output is correct
44 Correct 85 ms 7452 KB Output is correct
45 Correct 97 ms 7644 KB Output is correct
46 Correct 83 ms 7616 KB Output is correct
47 Correct 92 ms 7620 KB Output is correct
48 Correct 83 ms 7612 KB Output is correct
49 Correct 99 ms 7508 KB Output is correct
50 Correct 82 ms 7468 KB Output is correct
51 Correct 94 ms 7504 KB Output is correct
52 Correct 123 ms 7764 KB Output is correct
53 Correct 90 ms 7508 KB Output is correct
54 Correct 95 ms 7500 KB Output is correct
55 Correct 102 ms 7480 KB Output is correct
56 Correct 94 ms 7676 KB Output is correct
57 Correct 104 ms 7484 KB Output is correct
58 Correct 97 ms 7508 KB Output is correct