#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44
using namespace std;
const int INF = 1e6;
vector < vector <int> > pos;
inline int getmin(int x) {
int mn = 1e9;
for(int i = 1; i <= 3; i++) {
mn = min(mn, pos[i][x]);
}
return mn;
}
inline int getmax(int x) {
int mx = 0;
for(int i = 1; i <= 3; i++) {
mx = max(mx, pos[i][x]);
}
return mx;
}
struct SegTree {
struct Node {
int pref, sum;
int pos;
};
vector <Node> aint;
int n;
inline void init(int _n) {
n = _n;
aint.resize(4 * n + 1);
}
inline void refresh(int nod) {
aint[nod].sum = aint[2 * nod].sum + aint[2 * nod + 1].sum;
if(aint[2 * nod].pref <= aint[2 * nod + 1].pref + aint[2 * nod].sum) {
aint[nod].pref = aint[2 * nod].pref;
aint[nod].pos = aint[2 * nod].pos;
}
else {
aint[nod].pref = aint[2 * nod].sum + aint[2 * nod + 1].pref;
aint[nod].pos = aint[2 * nod + 1].pos;
}
}
void build(int nod, int left, int right, vector <int> &arr) {
if(left == right) {
aint[nod] = {arr[left], arr[left], left};
}
else {
int mid = (left + right) / 2;
build(2 * nod, left, mid, arr);
build(2 * nod + 1, mid + 1, right, arr);
refresh(nod);
}
}
void update(int nod, int left, int right, int pos, int val) {
if(left == right) {
aint[nod].sum += val;
aint[nod].pref += val;
aint[nod].pos = left;
}
else {
int mid = (left + right) / 2;
if(pos <= mid) update(2 * nod, left, mid, pos, val);
else update(2 * nod + 1, mid + 1, right, pos, val);
refresh(nod);
}
}
};
int main() {
//ifstream cin("A.in");
//ofstream cout("A.out");
int i, j, n, q;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> q;
vector < vector <int> > arr(4, vector <int>(n + 1));
pos.resize(4, vector <int>(n + 1));
for(i = 1; i <= 3; i++) {
for(j = 1; j <= n; j++) {
cin >> arr[i][j];
pos[i][arr[i][j]] = j;
}
}
SegTree st; st.init(n);
vector <int> aux(n + 1);
for(i = 1; i <= n; i++) {
aux[getmin(i)]++;
aux[getmax(i)]--;
}
st.build(1, 1, n, aux);
while(q > 0) {
q--;
int type;
cin>> type;
if(type == 1) {
int x;
cin >> x;
cout << (st.aint[1].pos >= getmax(x) ? "DA" : "NE") << "\n";
}
else {
int p, a, b;
cin >> p >> a >> b;
st.update(1, 1, n, getmin(a), -1);
st.update(1, 1, n, getmax(a), 1);
st.update(1, 1, n, getmin(b), -1);
st.update(1, 1, n, getmax(b), 1);
swap(arr[p][pos[p][a]], arr[p][pos[p][b]]);
swap(pos[p][a], pos[p][b]);
st.update(1, 1, n, getmin(a), 1);
st.update(1, 1, n, getmax(a), -1);
st.update(1, 1, n, getmin(b), 1);
st.update(1, 1, n, getmax(b), -1);
}
}
//cin.close();
//cout.close();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
43 ms |
10264 KB |
Output is correct |
14 |
Correct |
49 ms |
10224 KB |
Output is correct |
15 |
Correct |
42 ms |
10220 KB |
Output is correct |
16 |
Correct |
42 ms |
10228 KB |
Output is correct |
17 |
Correct |
43 ms |
10308 KB |
Output is correct |
18 |
Correct |
40 ms |
10356 KB |
Output is correct |
19 |
Correct |
40 ms |
10192 KB |
Output is correct |
20 |
Correct |
40 ms |
10352 KB |
Output is correct |
21 |
Correct |
40 ms |
10224 KB |
Output is correct |
22 |
Correct |
40 ms |
10352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
11440 KB |
Output is correct |
2 |
Correct |
62 ms |
11376 KB |
Output is correct |
3 |
Correct |
67 ms |
11376 KB |
Output is correct |
4 |
Correct |
82 ms |
11332 KB |
Output is correct |
5 |
Correct |
66 ms |
11420 KB |
Output is correct |
6 |
Correct |
65 ms |
11348 KB |
Output is correct |
7 |
Correct |
62 ms |
11504 KB |
Output is correct |
8 |
Correct |
61 ms |
11304 KB |
Output is correct |
9 |
Correct |
62 ms |
11376 KB |
Output is correct |
10 |
Correct |
63 ms |
11252 KB |
Output is correct |
11 |
Correct |
60 ms |
11328 KB |
Output is correct |
12 |
Correct |
59 ms |
11252 KB |
Output is correct |
13 |
Correct |
62 ms |
11500 KB |
Output is correct |
14 |
Correct |
63 ms |
11376 KB |
Output is correct |
15 |
Correct |
60 ms |
11372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
512 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
43 ms |
10264 KB |
Output is correct |
14 |
Correct |
49 ms |
10224 KB |
Output is correct |
15 |
Correct |
42 ms |
10220 KB |
Output is correct |
16 |
Correct |
42 ms |
10228 KB |
Output is correct |
17 |
Correct |
43 ms |
10308 KB |
Output is correct |
18 |
Correct |
40 ms |
10356 KB |
Output is correct |
19 |
Correct |
40 ms |
10192 KB |
Output is correct |
20 |
Correct |
40 ms |
10352 KB |
Output is correct |
21 |
Correct |
40 ms |
10224 KB |
Output is correct |
22 |
Correct |
40 ms |
10352 KB |
Output is correct |
23 |
Correct |
64 ms |
11440 KB |
Output is correct |
24 |
Correct |
62 ms |
11376 KB |
Output is correct |
25 |
Correct |
67 ms |
11376 KB |
Output is correct |
26 |
Correct |
82 ms |
11332 KB |
Output is correct |
27 |
Correct |
66 ms |
11420 KB |
Output is correct |
28 |
Correct |
65 ms |
11348 KB |
Output is correct |
29 |
Correct |
62 ms |
11504 KB |
Output is correct |
30 |
Correct |
61 ms |
11304 KB |
Output is correct |
31 |
Correct |
62 ms |
11376 KB |
Output is correct |
32 |
Correct |
63 ms |
11252 KB |
Output is correct |
33 |
Correct |
60 ms |
11328 KB |
Output is correct |
34 |
Correct |
59 ms |
11252 KB |
Output is correct |
35 |
Correct |
62 ms |
11500 KB |
Output is correct |
36 |
Correct |
63 ms |
11376 KB |
Output is correct |
37 |
Correct |
60 ms |
11372 KB |
Output is correct |
38 |
Correct |
173 ms |
11600 KB |
Output is correct |
39 |
Correct |
80 ms |
11296 KB |
Output is correct |
40 |
Correct |
180 ms |
11716 KB |
Output is correct |
41 |
Correct |
89 ms |
11500 KB |
Output is correct |
42 |
Correct |
94 ms |
11628 KB |
Output is correct |
43 |
Correct |
175 ms |
11632 KB |
Output is correct |
44 |
Correct |
85 ms |
11420 KB |
Output is correct |
45 |
Correct |
96 ms |
11504 KB |
Output is correct |
46 |
Correct |
84 ms |
11492 KB |
Output is correct |
47 |
Correct |
90 ms |
11472 KB |
Output is correct |
48 |
Correct |
81 ms |
11352 KB |
Output is correct |
49 |
Correct |
102 ms |
11632 KB |
Output is correct |
50 |
Correct |
78 ms |
11468 KB |
Output is correct |
51 |
Correct |
94 ms |
11500 KB |
Output is correct |
52 |
Correct |
171 ms |
11756 KB |
Output is correct |
53 |
Correct |
89 ms |
11500 KB |
Output is correct |
54 |
Correct |
92 ms |
11380 KB |
Output is correct |
55 |
Correct |
98 ms |
11508 KB |
Output is correct |
56 |
Correct |
102 ms |
11500 KB |
Output is correct |
57 |
Correct |
89 ms |
11504 KB |
Output is correct |
58 |
Correct |
131 ms |
11500 KB |
Output is correct |