#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
const int MAXN = 100010;
const int MX = 1 << 17;
int N, Q;
int A[3][MAXN];
int idx[3][MAXN];
lint s[MAXN];
lint seg[2 * MX], lazy[2 * MX];
void mkseg(int idx, int l, int r) {
if(l == r) seg[idx] = s[l] - (lint)l * (l + 1);
else {
int m = (l + r) / 2;
mkseg(idx * 2, l, m);
mkseg(idx * 2 + 1, m + 1, r);
seg[idx] = min(seg[idx * 2], seg[idx * 2 + 1]);
}
}
void spreadlazy(int idx) {
seg[idx * 2] += lazy[idx];
seg[idx * 2 + 1] += lazy[idx];
lazy[idx * 2] += lazy[idx];
lazy[idx * 2 + 1] += lazy[idx];
lazy[idx] = 0;
}
int gseg(int idx, int l, int r) {
if(seg[idx] > 0) return -1;
if(l == r) return l;
int m = (l + r) / 2;
spreadlazy(idx);
int t = gseg(idx * 2, l, m);
return t == -1 ? gseg(idx * 2 + 1, m + 1, r) : t;
}
void updseg(int idx, int l, int r, int x, int z) {
if(x <= l) {
seg[idx] += z;
lazy[idx] += z;
}
else if(x <= r) {
int m = (l + r) / 2;
updseg(idx * 2, l, m, x, z);
updseg(idx * 2 + 1, m + 1, r, x, z);
seg[idx] = min(seg[idx * 2], seg[idx * 2 + 1]) + lazy[idx];
}
}
void updseg(int x, int z) { updseg(1, 0, N - 1, x, z); }
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> N >> Q;
for(int i = 0; i < 3; i++) for(int j = 0; j < N; j++) cin >> A[i][j];
for(int i = 0; i < 3; i++) for(int j = 0; j < N; j++) idx[i][A[i][j]] = j;
for(int i = 0; i < N; i++)
s[i] = (i > 0 ? s[i - 1] : 0) + idx[0][A[1][i]] + idx[0][A[2][i]];
mkseg(1, 0, N - 1);
while(Q--) {
int c;
cin >> c;
if(c == 1) {
int x;
cin >> x;
cout << (idx[0][x] <= gseg(1, 0, N - 1) ? "DA" : "NE") << "\n";
}
else {
int p, a, b;
cin >> p >> a >> b;
if(--p == 0) {
for(int i = 1; i < 3; i++) {
updseg(idx[i][a], idx[0][b] - idx[0][a]);
updseg(idx[i][b], idx[0][a] - idx[0][b]);
}
swap(idx[0][a], idx[0][b]);
}
else {
updseg(idx[p][a], idx[0][b] - idx[0][a]);
updseg(idx[p][b], idx[0][a] - idx[0][b]);
swap(idx[p][a], idx[p][b]);
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
504 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
504 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
380 KB |
Output is correct |
12 |
Correct |
3 ms |
508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
504 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
504 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
380 KB |
Output is correct |
12 |
Correct |
3 ms |
508 KB |
Output is correct |
13 |
Correct |
38 ms |
7388 KB |
Output is correct |
14 |
Correct |
45 ms |
7416 KB |
Output is correct |
15 |
Correct |
39 ms |
7416 KB |
Output is correct |
16 |
Correct |
39 ms |
7292 KB |
Output is correct |
17 |
Correct |
39 ms |
7288 KB |
Output is correct |
18 |
Correct |
39 ms |
7260 KB |
Output is correct |
19 |
Correct |
39 ms |
7300 KB |
Output is correct |
20 |
Correct |
39 ms |
7416 KB |
Output is correct |
21 |
Correct |
40 ms |
7288 KB |
Output is correct |
22 |
Correct |
39 ms |
7380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
75 ms |
5880 KB |
Output is correct |
2 |
Correct |
73 ms |
5896 KB |
Output is correct |
3 |
Correct |
77 ms |
5960 KB |
Output is correct |
4 |
Correct |
84 ms |
5912 KB |
Output is correct |
5 |
Correct |
76 ms |
5880 KB |
Output is correct |
6 |
Correct |
93 ms |
5852 KB |
Output is correct |
7 |
Correct |
75 ms |
5880 KB |
Output is correct |
8 |
Correct |
84 ms |
5880 KB |
Output is correct |
9 |
Correct |
80 ms |
5880 KB |
Output is correct |
10 |
Correct |
76 ms |
5808 KB |
Output is correct |
11 |
Correct |
73 ms |
5880 KB |
Output is correct |
12 |
Correct |
77 ms |
5880 KB |
Output is correct |
13 |
Correct |
88 ms |
5880 KB |
Output is correct |
14 |
Correct |
79 ms |
5852 KB |
Output is correct |
15 |
Correct |
74 ms |
5880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
504 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
504 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
380 KB |
Output is correct |
12 |
Correct |
3 ms |
508 KB |
Output is correct |
13 |
Correct |
38 ms |
7388 KB |
Output is correct |
14 |
Correct |
45 ms |
7416 KB |
Output is correct |
15 |
Correct |
39 ms |
7416 KB |
Output is correct |
16 |
Correct |
39 ms |
7292 KB |
Output is correct |
17 |
Correct |
39 ms |
7288 KB |
Output is correct |
18 |
Correct |
39 ms |
7260 KB |
Output is correct |
19 |
Correct |
39 ms |
7300 KB |
Output is correct |
20 |
Correct |
39 ms |
7416 KB |
Output is correct |
21 |
Correct |
40 ms |
7288 KB |
Output is correct |
22 |
Correct |
39 ms |
7380 KB |
Output is correct |
23 |
Correct |
75 ms |
5880 KB |
Output is correct |
24 |
Correct |
73 ms |
5896 KB |
Output is correct |
25 |
Correct |
77 ms |
5960 KB |
Output is correct |
26 |
Correct |
84 ms |
5912 KB |
Output is correct |
27 |
Correct |
76 ms |
5880 KB |
Output is correct |
28 |
Correct |
93 ms |
5852 KB |
Output is correct |
29 |
Correct |
75 ms |
5880 KB |
Output is correct |
30 |
Correct |
84 ms |
5880 KB |
Output is correct |
31 |
Correct |
80 ms |
5880 KB |
Output is correct |
32 |
Correct |
76 ms |
5808 KB |
Output is correct |
33 |
Correct |
73 ms |
5880 KB |
Output is correct |
34 |
Correct |
77 ms |
5880 KB |
Output is correct |
35 |
Correct |
88 ms |
5880 KB |
Output is correct |
36 |
Correct |
79 ms |
5852 KB |
Output is correct |
37 |
Correct |
74 ms |
5880 KB |
Output is correct |
38 |
Correct |
132 ms |
10700 KB |
Output is correct |
39 |
Correct |
86 ms |
8440 KB |
Output is correct |
40 |
Correct |
130 ms |
10616 KB |
Output is correct |
41 |
Correct |
98 ms |
8440 KB |
Output is correct |
42 |
Correct |
98 ms |
8604 KB |
Output is correct |
43 |
Correct |
138 ms |
10616 KB |
Output is correct |
44 |
Correct |
91 ms |
8444 KB |
Output is correct |
45 |
Correct |
94 ms |
8696 KB |
Output is correct |
46 |
Correct |
83 ms |
8440 KB |
Output is correct |
47 |
Correct |
92 ms |
8568 KB |
Output is correct |
48 |
Correct |
84 ms |
8444 KB |
Output is correct |
49 |
Correct |
95 ms |
10104 KB |
Output is correct |
50 |
Correct |
85 ms |
8568 KB |
Output is correct |
51 |
Correct |
92 ms |
8516 KB |
Output is correct |
52 |
Correct |
118 ms |
9464 KB |
Output is correct |
53 |
Correct |
97 ms |
8648 KB |
Output is correct |
54 |
Correct |
99 ms |
8440 KB |
Output is correct |
55 |
Correct |
98 ms |
8572 KB |
Output is correct |
56 |
Correct |
91 ms |
8568 KB |
Output is correct |
57 |
Correct |
87 ms |
8440 KB |
Output is correct |
58 |
Correct |
114 ms |
10488 KB |
Output is correct |