Submission #957234

# Submission time Handle Problem Language Result Execution time Memory
957234 2024-04-03T09:20:34 Z lovrot Tenis (COI19_tenis) C++17
100 / 100
166 ms 9276 KB
#include <algorithm> 
#include <cstdio> 
#include <vector>

using namespace std; 

const int LOG = 17;
const int N = 1 << LOG;
const int OO = 2e9;

int PR[2 * N], M[2 * N], I[2 * N]; 

void propagate(int x) {
	if(x >= N) return;
	M[2 * x] += PR[x];
	M[2 * x + 1] += PR[x];
	PR[2 * x] += PR[x];
	PR[2 * x + 1] += PR[x];
	PR[x] = 0;
}

void update(int l, int r, int val, int x = 1, int lo = 0, int hi = N) {
	if(r <= lo || hi <= l) return;
	if(l <= lo && hi <= r) {
		PR[x] += val;
		M[x] += val;
		return; 
	}
	propagate(x); 
	int mi = (lo + hi) / 2;
	update(l, r, val, 2 * x, lo, mi); 
	update(l, r, val, 2 * x + 1, mi, hi); 
	M[x] = min(M[2 * x], M[2 * x + 1]);
	if(M[x] == M[2 * x]) I[x] = I[2 * x];
	else I[x] = I[2 * x + 1];
}

int n, q, T[3][N];
int P[3][N];

int right(int x) {
	return max({P[0][x], P[1][x], P[2][x]});
}

int main() {
	for(int i = N; i < 2 * N; ++i) I[i] = i - N;

	scanf("%d%d", &n, &q);
	for(int i = 0; i < 3; ++i)
		for(int j = 0; j < n; ++j) {
			scanf("%d", &T[i][j]);
			P[i][T[i][j] - 1] = j;
		}
	
	update(n, N, OO);
	for(int i = 0; i < n; ++i) {
		update(i, i + 1, i + 1); 
		update(right(i), N, -1); 
//		printf("%d %d\n", i, right(i));
	}
	
//	printf("%d %d\n", M[1], I[1]);
	for(; q--; ) {
		int t; scanf("%d", &t); 
		
		if(t == 1) {
			int x; scanf("%d", &x); --x;
			printf("%s\n", right(x) <= I[1] ? "DA" : "NE");
		} else {
			int p, a, b; scanf("%d%d%d", &p, &a, &b); --p; --a; --b;
			update(right(a), N, 1); 
			update(right(b), N, 1); 

			swap(P[p][a], P[p][b]);
			swap(T[p][P[p][a]], T[p][P[p][b]]);

			update(right(a), N, -1); 
			update(right(b), N, -1); 
		}
	}
	return 0;
}

Compilation message

tenis.cpp: In function 'int main()':
tenis.cpp:48:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |  scanf("%d%d", &n, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~
tenis.cpp:51:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |    scanf("%d", &T[i][j]);
      |    ~~~~~^~~~~~~~~~~~~~~~
tenis.cpp:64:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |   int t; scanf("%d", &t);
      |          ~~~~~^~~~~~~~~~
tenis.cpp:67:16: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |    int x; scanf("%d", &x); --x;
      |           ~~~~~^~~~~~~~~~
tenis.cpp:70:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |    int p, a, b; scanf("%d%d%d", &p, &a, &b); --p; --a; --b;
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 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 2 ms 4444 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 2 ms 4696 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 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 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 2 ms 4444 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 2 ms 4696 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 71 ms 7716 KB Output is correct
14 Correct 71 ms 7712 KB Output is correct
15 Correct 70 ms 7804 KB Output is correct
16 Correct 78 ms 7628 KB Output is correct
17 Correct 69 ms 7812 KB Output is correct
18 Correct 76 ms 7772 KB Output is correct
19 Correct 72 ms 7760 KB Output is correct
20 Correct 71 ms 7764 KB Output is correct
21 Correct 70 ms 7760 KB Output is correct
22 Correct 70 ms 7720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 95 ms 8852 KB Output is correct
2 Correct 93 ms 8768 KB Output is correct
3 Correct 94 ms 8792 KB Output is correct
4 Correct 92 ms 8736 KB Output is correct
5 Correct 95 ms 8848 KB Output is correct
6 Correct 93 ms 8788 KB Output is correct
7 Correct 92 ms 8784 KB Output is correct
8 Correct 91 ms 8788 KB Output is correct
9 Correct 93 ms 8764 KB Output is correct
10 Correct 90 ms 8772 KB Output is correct
11 Correct 93 ms 8784 KB Output is correct
12 Correct 92 ms 8788 KB Output is correct
13 Correct 101 ms 8768 KB Output is correct
14 Correct 90 ms 8784 KB Output is correct
15 Correct 92 ms 8768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 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 2 ms 4444 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 2 ms 4696 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 71 ms 7716 KB Output is correct
14 Correct 71 ms 7712 KB Output is correct
15 Correct 70 ms 7804 KB Output is correct
16 Correct 78 ms 7628 KB Output is correct
17 Correct 69 ms 7812 KB Output is correct
18 Correct 76 ms 7772 KB Output is correct
19 Correct 72 ms 7760 KB Output is correct
20 Correct 71 ms 7764 KB Output is correct
21 Correct 70 ms 7760 KB Output is correct
22 Correct 70 ms 7720 KB Output is correct
23 Correct 95 ms 8852 KB Output is correct
24 Correct 93 ms 8768 KB Output is correct
25 Correct 94 ms 8792 KB Output is correct
26 Correct 92 ms 8736 KB Output is correct
27 Correct 95 ms 8848 KB Output is correct
28 Correct 93 ms 8788 KB Output is correct
29 Correct 92 ms 8784 KB Output is correct
30 Correct 91 ms 8788 KB Output is correct
31 Correct 93 ms 8764 KB Output is correct
32 Correct 90 ms 8772 KB Output is correct
33 Correct 93 ms 8784 KB Output is correct
34 Correct 92 ms 8788 KB Output is correct
35 Correct 101 ms 8768 KB Output is correct
36 Correct 90 ms 8784 KB Output is correct
37 Correct 92 ms 8768 KB Output is correct
38 Correct 157 ms 9012 KB Output is correct
39 Correct 109 ms 8840 KB Output is correct
40 Correct 160 ms 9048 KB Output is correct
41 Correct 124 ms 8788 KB Output is correct
42 Correct 124 ms 9044 KB Output is correct
43 Correct 157 ms 9080 KB Output is correct
44 Correct 111 ms 8784 KB Output is correct
45 Correct 132 ms 9232 KB Output is correct
46 Correct 111 ms 8768 KB Output is correct
47 Correct 118 ms 8784 KB Output is correct
48 Correct 114 ms 8784 KB Output is correct
49 Correct 125 ms 9048 KB Output is correct
50 Correct 108 ms 8784 KB Output is correct
51 Correct 120 ms 9060 KB Output is correct
52 Correct 166 ms 9276 KB Output is correct
53 Correct 115 ms 9044 KB Output is correct
54 Correct 123 ms 9012 KB Output is correct
55 Correct 123 ms 9040 KB Output is correct
56 Correct 129 ms 8992 KB Output is correct
57 Correct 122 ms 8788 KB Output is correct
58 Correct 128 ms 8788 KB Output is correct