#include <cstdio>
#include <algorithm>
using namespace std;
int n, pos[3][100001], seg[400001], seg2[400001];
void update(int v, int tl, int tr, int pos, int x) {
if (tl == tr) {
seg[v] += x;
seg2[v] += x;
} else {
int tm = (tl+tr) >> 1;
if (pos <= tm) update(v<<1, tl, tm, pos, x);
else update(v<<1|1, tm+1, tr, pos, x);
seg[v] = min(seg[v<<1], seg2[v<<1]+seg[v<<1|1]);
seg2[v] = seg2[v<<1]+seg2[v<<1|1];
}
}
int query(int v, int tl, int tr, int s) {
if (tl == tr) return tl;
int tm = (tl+tr) >> 1;
if (seg[v<<1] <= s) return query(v<<1, tl, tm, s);
return query(v<<1|1, tm+1, tr, s-seg2[v<<1]);
}
void change(int v, int x) {
update(1, 1, n, min(min(pos[0][v], pos[1][v]), pos[2][v]), x);
update(1, 1, n, max(max(pos[0][v], pos[1][v]), pos[2][v]), -x);
}
int main() {
int q, t, x, y, z, cur = -1;
scanf("%d%d", &n, &q);
for (int i=0; i<3; i++) {
for (int j=1; j<=n; j++) {
scanf("%d", &x);
pos[i][x] = j;
}
}
for (int i=1; i<=n; i++) change(i, 1);
while (q--) {
scanf("%d%d", &t, &x);
if (t == 1) printf(pos[0][x] <= (cur == -1 ? cur = query(1, 1, n, 0) : cur) ? "DA\n" : "NE\n");
else {
scanf("%d%d", &y, &z);
change(y, -1);
change(z, -1);
swap(pos[x-1][y], pos[x-1][z]);
change(y, 1);
change(z, 1);
cur = -1;
}
}
}
Compilation message
tenis.cpp: In function 'int main()':
tenis.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
34 | scanf("%d%d", &n, &q);
| ~~~~~^~~~~~~~~~~~~~~~
tenis.cpp:37:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
37 | scanf("%d", &x);
| ~~~~~^~~~~~~~~~
tenis.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
43 | scanf("%d%d", &t, &x);
| ~~~~~^~~~~~~~~~~~~~~~
tenis.cpp:46:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
46 | scanf("%d%d", &y, &z);
| ~~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
83 ms |
5356 KB |
Output is correct |
14 |
Correct |
87 ms |
5228 KB |
Output is correct |
15 |
Correct |
84 ms |
5228 KB |
Output is correct |
16 |
Correct |
83 ms |
5356 KB |
Output is correct |
17 |
Correct |
96 ms |
5324 KB |
Output is correct |
18 |
Correct |
83 ms |
5356 KB |
Output is correct |
19 |
Correct |
89 ms |
5356 KB |
Output is correct |
20 |
Correct |
99 ms |
5356 KB |
Output is correct |
21 |
Correct |
84 ms |
5484 KB |
Output is correct |
22 |
Correct |
82 ms |
5228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
106 ms |
6380 KB |
Output is correct |
2 |
Correct |
107 ms |
6380 KB |
Output is correct |
3 |
Correct |
116 ms |
6380 KB |
Output is correct |
4 |
Correct |
132 ms |
6508 KB |
Output is correct |
5 |
Correct |
120 ms |
6420 KB |
Output is correct |
6 |
Correct |
108 ms |
6380 KB |
Output is correct |
7 |
Correct |
113 ms |
6380 KB |
Output is correct |
8 |
Correct |
115 ms |
6508 KB |
Output is correct |
9 |
Correct |
109 ms |
6508 KB |
Output is correct |
10 |
Correct |
112 ms |
6380 KB |
Output is correct |
11 |
Correct |
108 ms |
6380 KB |
Output is correct |
12 |
Correct |
108 ms |
6252 KB |
Output is correct |
13 |
Correct |
112 ms |
6380 KB |
Output is correct |
14 |
Correct |
121 ms |
6508 KB |
Output is correct |
15 |
Correct |
110 ms |
6380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
83 ms |
5356 KB |
Output is correct |
14 |
Correct |
87 ms |
5228 KB |
Output is correct |
15 |
Correct |
84 ms |
5228 KB |
Output is correct |
16 |
Correct |
83 ms |
5356 KB |
Output is correct |
17 |
Correct |
96 ms |
5324 KB |
Output is correct |
18 |
Correct |
83 ms |
5356 KB |
Output is correct |
19 |
Correct |
89 ms |
5356 KB |
Output is correct |
20 |
Correct |
99 ms |
5356 KB |
Output is correct |
21 |
Correct |
84 ms |
5484 KB |
Output is correct |
22 |
Correct |
82 ms |
5228 KB |
Output is correct |
23 |
Correct |
106 ms |
6380 KB |
Output is correct |
24 |
Correct |
107 ms |
6380 KB |
Output is correct |
25 |
Correct |
116 ms |
6380 KB |
Output is correct |
26 |
Correct |
132 ms |
6508 KB |
Output is correct |
27 |
Correct |
120 ms |
6420 KB |
Output is correct |
28 |
Correct |
108 ms |
6380 KB |
Output is correct |
29 |
Correct |
113 ms |
6380 KB |
Output is correct |
30 |
Correct |
115 ms |
6508 KB |
Output is correct |
31 |
Correct |
109 ms |
6508 KB |
Output is correct |
32 |
Correct |
112 ms |
6380 KB |
Output is correct |
33 |
Correct |
108 ms |
6380 KB |
Output is correct |
34 |
Correct |
108 ms |
6252 KB |
Output is correct |
35 |
Correct |
112 ms |
6380 KB |
Output is correct |
36 |
Correct |
121 ms |
6508 KB |
Output is correct |
37 |
Correct |
110 ms |
6380 KB |
Output is correct |
38 |
Correct |
229 ms |
6764 KB |
Output is correct |
39 |
Correct |
138 ms |
6380 KB |
Output is correct |
40 |
Correct |
240 ms |
6692 KB |
Output is correct |
41 |
Correct |
146 ms |
6508 KB |
Output is correct |
42 |
Correct |
166 ms |
6636 KB |
Output is correct |
43 |
Correct |
266 ms |
6784 KB |
Output is correct |
44 |
Correct |
130 ms |
6380 KB |
Output is correct |
45 |
Correct |
162 ms |
6508 KB |
Output is correct |
46 |
Correct |
137 ms |
6400 KB |
Output is correct |
47 |
Correct |
153 ms |
6644 KB |
Output is correct |
48 |
Correct |
147 ms |
6508 KB |
Output is correct |
49 |
Correct |
160 ms |
6508 KB |
Output is correct |
50 |
Correct |
134 ms |
6508 KB |
Output is correct |
51 |
Correct |
192 ms |
6508 KB |
Output is correct |
52 |
Correct |
225 ms |
6892 KB |
Output is correct |
53 |
Correct |
148 ms |
6508 KB |
Output is correct |
54 |
Correct |
155 ms |
6508 KB |
Output is correct |
55 |
Correct |
183 ms |
6636 KB |
Output is correct |
56 |
Correct |
198 ms |
6508 KB |
Output is correct |
57 |
Correct |
141 ms |
6380 KB |
Output is correct |
58 |
Correct |
175 ms |
6508 KB |
Output is correct |