#include "bits/stdc++.h"
using namespace std;
#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif
const int N = 1e5 + 5;
int lazy[N * 2], seg[N * 2];
void push(int nd, int l, int r) {
if (!lazy[nd]) return;
seg[nd] += lazy[nd];
if (l != r) {
int mid = (l + r) >> 1;
int rs = nd + ((mid - l + 1) << 1);
lazy[nd + 1] += lazy[nd];
lazy[rs] += lazy[nd];
}
lazy[nd] = 0;
}
void upd(int nd, int l, int r, int s, int e, int v) {
push(nd, l, r);
if (l >= s && r <= e) {
lazy[nd] = v;
push(nd, l, r);
return;
}
int mid = (l + r) >> 1;
int rs = nd + ((mid - l + 1) << 1);
if (mid >= e) {
upd(nd + 1, l, mid, s, e, v);
push(rs, mid + 1, r);
} else {
if (mid < s) {
push(nd + 1, l, mid);
upd(rs, mid + 1, r, s, e, v);
} else {
upd(nd + 1, l, mid, s, e, v);
upd(rs, mid + 1, r, s, e, v);
}
}
seg[nd] = min(seg[nd + 1], seg[rs]);
}
int get(int nd, int l, int r) {
if (l == r) {
return l;
}
int mid = (l + r) >> 1;
int rs = nd + ((mid - l + 1) << 1);
push(nd + 1, l, mid);
push(rs, mid + 1, r);
if (seg[nd + 1] == -1) {
return get(nd + 1, l, mid);
}
return get(rs, mid + 1, r);
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
cin >> n >> q;
vector<vector<int>> a(3, vector<int> (n));
vector<vector<int>> idx(3, vector<int> (n));
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < n; ++j) {
cin >> a[i][j];
--a[i][j];
idx[i][a[i][j]] = j;
}
}
auto get_first = [&](int x) {
return min({idx[0][x], idx[1][x], idx[2][x]});
};
auto get_last = [&](int x) {
return max({idx[0][x], idx[1][x], idx[2][x]});
};
auto fill = [&](int x, int y) {
vector<int> ret;
for (int i = 0; i < 3; ++i) {
ret.push_back(idx[i][x]);
ret.push_back(idx[i][y]);
}
sort(ret.begin(), ret.end());
ret.resize(unique(ret.begin(), ret.end()) - ret.begin());
return ret;
};
auto get_val = [&](int col) {
return max({get_last(a[0][col]), get_last(a[1][col]), get_last(a[2][col])});
};
vector<int> b(n);
for (int i = 0; i < n; ++i) {
b[i] = get_val(i);
upd(0, 0, n - 1, i, i, b[i]);
upd(0, 0, n - 1, get_last(i), n - 1, -1);
}
while (q--) {
int tp;
cin >> tp;
if (tp == 1) {
int x;
cin >> x;
--x;
int f = get_first(x);
int c = get(0, 0, n - 1);
cout << (c >= f ? "DA" : "NE") << '\n';
} else {
int p, x, y;
cin >> p >> x >> y;
--p, --x, --y;
upd(0, 0, n - 1, get_last(x), n - 1, +1);
upd(0, 0, n - 1, get_last(y), n - 1, +1);
vector<int> cols = fill(x, y);
for (int i : cols) {
upd(0, 0, n - 1, i, i, -b[i]);
}
int px = idx[p][x];
int py = idx[p][y];
swap(idx[p][x], idx[p][y]);
a[p][px] = y;
a[p][py] = x;
upd(0, 0, n - 1, get_last(x), n - 1, -1);
upd(0, 0, n - 1, get_last(y), n - 1, -1);
for (int i : cols) {
b[i] = get_val(i);
upd(0, 0, n - 1, i, i, b[i]);
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
60 ms |
4560 KB |
Output is correct |
14 |
Correct |
65 ms |
4752 KB |
Output is correct |
15 |
Correct |
62 ms |
4552 KB |
Output is correct |
16 |
Correct |
60 ms |
4568 KB |
Output is correct |
17 |
Correct |
61 ms |
4564 KB |
Output is correct |
18 |
Correct |
62 ms |
4760 KB |
Output is correct |
19 |
Correct |
62 ms |
4728 KB |
Output is correct |
20 |
Correct |
60 ms |
4760 KB |
Output is correct |
21 |
Correct |
64 ms |
4744 KB |
Output is correct |
22 |
Correct |
64 ms |
4756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
5524 KB |
Output is correct |
2 |
Correct |
102 ms |
7500 KB |
Output is correct |
3 |
Correct |
89 ms |
7372 KB |
Output is correct |
4 |
Correct |
86 ms |
7432 KB |
Output is correct |
5 |
Correct |
89 ms |
7552 KB |
Output is correct |
6 |
Correct |
86 ms |
7448 KB |
Output is correct |
7 |
Correct |
83 ms |
7436 KB |
Output is correct |
8 |
Correct |
88 ms |
7444 KB |
Output is correct |
9 |
Correct |
84 ms |
7428 KB |
Output is correct |
10 |
Correct |
101 ms |
7268 KB |
Output is correct |
11 |
Correct |
85 ms |
7420 KB |
Output is correct |
12 |
Correct |
88 ms |
7304 KB |
Output is correct |
13 |
Correct |
86 ms |
7444 KB |
Output is correct |
14 |
Correct |
90 ms |
7428 KB |
Output is correct |
15 |
Correct |
85 ms |
7368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
60 ms |
4560 KB |
Output is correct |
14 |
Correct |
65 ms |
4752 KB |
Output is correct |
15 |
Correct |
62 ms |
4552 KB |
Output is correct |
16 |
Correct |
60 ms |
4568 KB |
Output is correct |
17 |
Correct |
61 ms |
4564 KB |
Output is correct |
18 |
Correct |
62 ms |
4760 KB |
Output is correct |
19 |
Correct |
62 ms |
4728 KB |
Output is correct |
20 |
Correct |
60 ms |
4760 KB |
Output is correct |
21 |
Correct |
64 ms |
4744 KB |
Output is correct |
22 |
Correct |
64 ms |
4756 KB |
Output is correct |
23 |
Correct |
82 ms |
5524 KB |
Output is correct |
24 |
Correct |
102 ms |
7500 KB |
Output is correct |
25 |
Correct |
89 ms |
7372 KB |
Output is correct |
26 |
Correct |
86 ms |
7432 KB |
Output is correct |
27 |
Correct |
89 ms |
7552 KB |
Output is correct |
28 |
Correct |
86 ms |
7448 KB |
Output is correct |
29 |
Correct |
83 ms |
7436 KB |
Output is correct |
30 |
Correct |
88 ms |
7444 KB |
Output is correct |
31 |
Correct |
84 ms |
7428 KB |
Output is correct |
32 |
Correct |
101 ms |
7268 KB |
Output is correct |
33 |
Correct |
85 ms |
7420 KB |
Output is correct |
34 |
Correct |
88 ms |
7304 KB |
Output is correct |
35 |
Correct |
86 ms |
7444 KB |
Output is correct |
36 |
Correct |
90 ms |
7428 KB |
Output is correct |
37 |
Correct |
85 ms |
7368 KB |
Output is correct |
38 |
Correct |
271 ms |
7728 KB |
Output is correct |
39 |
Correct |
137 ms |
7372 KB |
Output is correct |
40 |
Correct |
279 ms |
7900 KB |
Output is correct |
41 |
Correct |
162 ms |
7536 KB |
Output is correct |
42 |
Correct |
173 ms |
7712 KB |
Output is correct |
43 |
Correct |
274 ms |
7592 KB |
Output is correct |
44 |
Correct |
158 ms |
7964 KB |
Output is correct |
45 |
Correct |
181 ms |
7632 KB |
Output is correct |
46 |
Correct |
133 ms |
7600 KB |
Output is correct |
47 |
Correct |
171 ms |
7624 KB |
Output is correct |
48 |
Correct |
162 ms |
7528 KB |
Output is correct |
49 |
Correct |
167 ms |
7584 KB |
Output is correct |
50 |
Correct |
132 ms |
7880 KB |
Output is correct |
51 |
Correct |
172 ms |
7676 KB |
Output is correct |
52 |
Correct |
268 ms |
7624 KB |
Output is correct |
53 |
Correct |
156 ms |
7692 KB |
Output is correct |
54 |
Correct |
161 ms |
7664 KB |
Output is correct |
55 |
Correct |
184 ms |
7672 KB |
Output is correct |
56 |
Correct |
176 ms |
7688 KB |
Output is correct |
57 |
Correct |
137 ms |
7568 KB |
Output is correct |
58 |
Correct |
235 ms |
7628 KB |
Output is correct |