// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
template<class T> using V = vector<T>;
using vi = V<int>;
struct Seg {
const int ID = 0; int comb(int a, int b) { return min(a, b); }
vi seg, lazy; int N; void init(int n) {
for(N = 1; N < n;) N *= 2;
seg.assign(2 * N, ID); lazy.assign(2 * N, ID);
}
void push(int x, int L, int R) {
seg[x] += lazy[x];
if (L != R) for(int i = 0; i < 2; i++) lazy[2*x+i] += lazy[x];
lazy[x] = 0;
}
void pull(int x) { seg[x] = comb(seg[2*x], seg[2*x+1]); }
void upd(int l, int v, int x, int L, int R) { // the suffix starting at l
push(x, L, R); if (R < l) return;
// cout << L << " <-> " << R << endl;
if (l <= L) { lazy[x] += v; push(x, L, R); return; }
int M = (L + R) / 2; upd(l, v, 2 * x, L, M); upd(l, v, 2 * x + 1, M + 1, R);
pull(x);
}
void full(int x, int L, int R) {
push(x, L, R);
if (L == R) return;
int M = (L + R) / 2; full(2 * x, L, M); full(2 * x + 1, M + 1, R);
pull(x);
}
int find(int x, int L, int R) { // find first zero
push(x, L, R); if (seg[x] > 0) return -1;
if (L == R) return L;
int M = (L + R) / 2;
int res = find(2 * x, L, M);
if (res == -1) return find(2 * x + 1, M + 1, R);
return res;
}
void upd(int l, int v) { upd(l, v, 1, 0, N - 1); }
int find() { return find(1, 0, N - 1); }
void full() { full(1, 0, N - 1); }
};
int main() {
cin.tie(0)->sync_with_stdio(0);
int N, Q; cin >> N >> Q;
V<vi> A(3, vi(N));
for(int t = 0; t < 3; t++) for(int i = 0; i < N; i++) { int x; cin >> x; --x; A[t][x] = i; }
Seg st; st.init(2 * (N + 1));
// cout << 1 << endl;
auto upd = [&](int i, int d = +1) {
// cout << i << endl;
int l = min({A[0][i], A[1][i], A[2][i]}), r = max({A[0][i], A[1][i], A[2][i]});
// cout << l << " " << r + 1 << endl;
st.upd(2 * l, +1 * d); st.upd(2 * r + 1, -1 * d);
};
for(int i = 0; i < N; i++) upd(i);
// cout << 1 << endl;
// st.full();
// for(int i = 0; i <= 2 * N; i++) cout << i << " => " << st.seg[i + st.N] << endl;
// cout << endl;
for(int q = 0; q < Q; q++) {
// st.full();
// for(int i = 0; i <= 2 * N; i++) cout << i << " => " << st.seg[i + st.N] << endl;
// cout << endl;
int t; cin >> t;
if (t == 1) {
int x; cin >> x; --x;
int fir = st.find() / 2;
// cout << "FIR: " << fir << endl;
cout << (A[0][x] <= fir ? "DA" : "NE") << nl;
} else {
int c, x, y; cin >> c >> x >> y; --c, --x, --y;
upd(x, -1); upd(y, -1);
swap(A[c][x], A[c][y]);
upd(x); upd(y);
}
}
exit(0-0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
452 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
452 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
452 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
500 KB |
Output is correct |
13 |
Correct |
74 ms |
7388 KB |
Output is correct |
14 |
Correct |
76 ms |
7644 KB |
Output is correct |
15 |
Correct |
80 ms |
7372 KB |
Output is correct |
16 |
Correct |
74 ms |
7376 KB |
Output is correct |
17 |
Correct |
79 ms |
7456 KB |
Output is correct |
18 |
Correct |
75 ms |
7384 KB |
Output is correct |
19 |
Correct |
74 ms |
7432 KB |
Output is correct |
20 |
Correct |
75 ms |
7380 KB |
Output is correct |
21 |
Correct |
74 ms |
7380 KB |
Output is correct |
22 |
Correct |
74 ms |
7368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
98 ms |
8336 KB |
Output is correct |
2 |
Correct |
98 ms |
8408 KB |
Output is correct |
3 |
Correct |
97 ms |
8392 KB |
Output is correct |
4 |
Correct |
105 ms |
8396 KB |
Output is correct |
5 |
Correct |
97 ms |
8280 KB |
Output is correct |
6 |
Correct |
115 ms |
8396 KB |
Output is correct |
7 |
Correct |
100 ms |
8416 KB |
Output is correct |
8 |
Correct |
107 ms |
8396 KB |
Output is correct |
9 |
Correct |
98 ms |
8428 KB |
Output is correct |
10 |
Correct |
98 ms |
8268 KB |
Output is correct |
11 |
Correct |
105 ms |
8504 KB |
Output is correct |
12 |
Correct |
96 ms |
8380 KB |
Output is correct |
13 |
Correct |
109 ms |
8412 KB |
Output is correct |
14 |
Correct |
98 ms |
8508 KB |
Output is correct |
15 |
Correct |
97 ms |
8392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
452 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
500 KB |
Output is correct |
13 |
Correct |
74 ms |
7388 KB |
Output is correct |
14 |
Correct |
76 ms |
7644 KB |
Output is correct |
15 |
Correct |
80 ms |
7372 KB |
Output is correct |
16 |
Correct |
74 ms |
7376 KB |
Output is correct |
17 |
Correct |
79 ms |
7456 KB |
Output is correct |
18 |
Correct |
75 ms |
7384 KB |
Output is correct |
19 |
Correct |
74 ms |
7432 KB |
Output is correct |
20 |
Correct |
75 ms |
7380 KB |
Output is correct |
21 |
Correct |
74 ms |
7380 KB |
Output is correct |
22 |
Correct |
74 ms |
7368 KB |
Output is correct |
23 |
Correct |
98 ms |
8336 KB |
Output is correct |
24 |
Correct |
98 ms |
8408 KB |
Output is correct |
25 |
Correct |
97 ms |
8392 KB |
Output is correct |
26 |
Correct |
105 ms |
8396 KB |
Output is correct |
27 |
Correct |
97 ms |
8280 KB |
Output is correct |
28 |
Correct |
115 ms |
8396 KB |
Output is correct |
29 |
Correct |
100 ms |
8416 KB |
Output is correct |
30 |
Correct |
107 ms |
8396 KB |
Output is correct |
31 |
Correct |
98 ms |
8428 KB |
Output is correct |
32 |
Correct |
98 ms |
8268 KB |
Output is correct |
33 |
Correct |
105 ms |
8504 KB |
Output is correct |
34 |
Correct |
96 ms |
8380 KB |
Output is correct |
35 |
Correct |
109 ms |
8412 KB |
Output is correct |
36 |
Correct |
98 ms |
8508 KB |
Output is correct |
37 |
Correct |
97 ms |
8392 KB |
Output is correct |
38 |
Correct |
235 ms |
8572 KB |
Output is correct |
39 |
Correct |
138 ms |
8400 KB |
Output is correct |
40 |
Correct |
239 ms |
8844 KB |
Output is correct |
41 |
Correct |
171 ms |
8656 KB |
Output is correct |
42 |
Correct |
170 ms |
8652 KB |
Output is correct |
43 |
Correct |
233 ms |
8652 KB |
Output is correct |
44 |
Correct |
149 ms |
8396 KB |
Output is correct |
45 |
Correct |
178 ms |
9168 KB |
Output is correct |
46 |
Correct |
137 ms |
8400 KB |
Output is correct |
47 |
Correct |
170 ms |
8424 KB |
Output is correct |
48 |
Correct |
137 ms |
8400 KB |
Output is correct |
49 |
Correct |
183 ms |
8916 KB |
Output is correct |
50 |
Correct |
136 ms |
8412 KB |
Output is correct |
51 |
Correct |
167 ms |
8652 KB |
Output is correct |
52 |
Correct |
245 ms |
8908 KB |
Output is correct |
53 |
Correct |
158 ms |
8668 KB |
Output is correct |
54 |
Correct |
165 ms |
8660 KB |
Output is correct |
55 |
Correct |
192 ms |
8660 KB |
Output is correct |
56 |
Correct |
168 ms |
8696 KB |
Output is correct |
57 |
Correct |
137 ms |
8396 KB |
Output is correct |
58 |
Correct |
168 ms |
8652 KB |
Output is correct |