#include <bits/stdc++.h>
#define mp make_pair
#define F first
#define S second
using namespace std;
typedef pair<int, int> pii;
int n, q;
struct NODE{
int p, l;
}tree[400010];
void prop(int nd, int s, int e){
tree[nd].p+=tree[nd].l;
if(s!=e){
tree[nd*2].l+=tree[nd].l;
tree[nd*2+1].l+=tree[nd].l;
}
tree[nd].l=0;
}
void alter(int nd, int s, int e, int a, int b, int val){
if(e<a||s>b||a>b)return;
if(a<=s&&e<=b){
tree[nd].l+=val;
return;
}
prop(nd, s, e);
alter(nd*2, s, (s+e)/2, a, b, val);
alter(nd*2+1, (s+e)/2+1, e, a, b, val);
tree[nd].p=min(tree[nd*2].p+tree[nd*2].l, tree[nd*2+1].p+tree[nd*2+1].l);
}
int query(int nd, int s, int e){
prop(nd, s, e);
if(tree[nd].p)return 0;
if(s==e)return s;
int ret=query(nd*2, s, (s+e)/2);
if(ret)return ret;
return query(nd*2+1, (s+e)/2+1, e);
}
int arr[100010];
pii rnk[100010];
int main(){
scanf("%d %d", &n, &q);
for(int i=1; i<=n; i++){
int a;
scanf("%d", &a);
arr[a]=i;
}
for(int i=1; i<=n; i++){
int a;
scanf("%d", &a);
rnk[arr[a]].F=i;
alter(1, 1, n, min(arr[a], i), max(arr[a], i)-1, 1);
}
for(int i=1; i<=n; i++){
int a;
scanf("%d", &a);
rnk[arr[a]].S=i;
alter(1, 1, n, min(arr[a], i), max(arr[a], i)-1, 1);
}
for(int i=1; i<=q; i++){
int qu;
scanf("%d", &qu);
if(qu==1){
int a;
scanf("%d", &a);
if(query(1, 1, n)>=arr[a])puts("DA");
else puts("NE");
}
else{
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if(a==1){
alter(1, 1, n, min(arr[b], rnk[arr[b]].F), max(arr[b], rnk[arr[b]].F)-1, -1);
alter(1, 1, n, min(arr[b], rnk[arr[b]].S), max(arr[b], rnk[arr[b]].S)-1, -1);
alter(1, 1, n, min(arr[c], rnk[arr[c]].F), max(arr[c], rnk[arr[c]].F)-1, -1);
alter(1, 1, n, min(arr[c], rnk[arr[c]].S), max(arr[c], rnk[arr[c]].S)-1, -1);
swap(rnk[arr[b]], rnk[arr[c]]);
swap(arr[b], arr[c]);
alter(1, 1, n, min(arr[b], rnk[arr[b]].F), max(arr[b], rnk[arr[b]].F)-1, 1);
alter(1, 1, n, min(arr[b], rnk[arr[b]].S), max(arr[b], rnk[arr[b]].S)-1, 1);
alter(1, 1, n, min(arr[c], rnk[arr[c]].F), max(arr[c], rnk[arr[c]].F)-1, 1);
alter(1, 1, n, min(arr[c], rnk[arr[c]].S), max(arr[c], rnk[arr[c]].S)-1, 1);
}
if(a==2){
alter(1, 1, n, min(arr[b], rnk[arr[b]].F), max(arr[b], rnk[arr[b]].F)-1, -1);
alter(1, 1, n, min(arr[c], rnk[arr[c]].F), max(arr[c], rnk[arr[c]].F)-1, -1);
swap(rnk[arr[b]].F, rnk[arr[c]].F);
alter(1, 1, n, min(arr[b], rnk[arr[b]].F), max(arr[b], rnk[arr[b]].F)-1, 1);
alter(1, 1, n, min(arr[c], rnk[arr[c]].F), max(arr[c], rnk[arr[c]].F)-1, 1);
}
if(a==3){
alter(1, 1, n, min(arr[b], rnk[arr[b]].S), max(arr[b], rnk[arr[b]].S)-1, -1);
alter(1, 1, n, min(arr[c], rnk[arr[c]].S), max(arr[c], rnk[arr[c]].S)-1, -1);
swap(rnk[arr[b]].S, rnk[arr[c]].S);
alter(1, 1, n, min(arr[b], rnk[arr[b]].S), max(arr[b], rnk[arr[b]].S)-1, 1);
alter(1, 1, n, min(arr[c], rnk[arr[c]].S), max(arr[c], rnk[arr[c]].S)-1, 1);
}
}
}
}
Compilation message
tenis.cpp: In function 'int main()':
tenis.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &q);
~~~~~^~~~~~~~~~~~~~~~~
tenis.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a);
~~~~~^~~~~~~~~~
tenis.cpp:50:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a);
~~~~~^~~~~~~~~~
tenis.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a);
~~~~~^~~~~~~~~~
tenis.cpp:62:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &qu);
~~~~~^~~~~~~~~~~
tenis.cpp:65:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a);
~~~~~^~~~~~~~~~
tenis.cpp:71:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &a, &b, &c);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
512 KB |
Output is correct |
10 |
Correct |
6 ms |
384 KB |
Output is correct |
11 |
Correct |
6 ms |
384 KB |
Output is correct |
12 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
512 KB |
Output is correct |
10 |
Correct |
6 ms |
384 KB |
Output is correct |
11 |
Correct |
6 ms |
384 KB |
Output is correct |
12 |
Correct |
6 ms |
384 KB |
Output is correct |
13 |
Correct |
100 ms |
4488 KB |
Output is correct |
14 |
Correct |
113 ms |
5240 KB |
Output is correct |
15 |
Correct |
108 ms |
5240 KB |
Output is correct |
16 |
Correct |
106 ms |
5240 KB |
Output is correct |
17 |
Correct |
96 ms |
5200 KB |
Output is correct |
18 |
Correct |
101 ms |
5240 KB |
Output is correct |
19 |
Correct |
101 ms |
5240 KB |
Output is correct |
20 |
Correct |
117 ms |
5240 KB |
Output is correct |
21 |
Correct |
105 ms |
5296 KB |
Output is correct |
22 |
Correct |
102 ms |
5240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
152 ms |
5624 KB |
Output is correct |
2 |
Correct |
140 ms |
6520 KB |
Output is correct |
3 |
Correct |
152 ms |
6392 KB |
Output is correct |
4 |
Correct |
131 ms |
6392 KB |
Output is correct |
5 |
Correct |
144 ms |
6520 KB |
Output is correct |
6 |
Correct |
138 ms |
6392 KB |
Output is correct |
7 |
Correct |
148 ms |
6392 KB |
Output is correct |
8 |
Correct |
130 ms |
6392 KB |
Output is correct |
9 |
Correct |
144 ms |
6392 KB |
Output is correct |
10 |
Correct |
157 ms |
6392 KB |
Output is correct |
11 |
Correct |
145 ms |
6392 KB |
Output is correct |
12 |
Correct |
135 ms |
6392 KB |
Output is correct |
13 |
Correct |
142 ms |
6392 KB |
Output is correct |
14 |
Correct |
139 ms |
6392 KB |
Output is correct |
15 |
Correct |
144 ms |
6264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
512 KB |
Output is correct |
10 |
Correct |
6 ms |
384 KB |
Output is correct |
11 |
Correct |
6 ms |
384 KB |
Output is correct |
12 |
Correct |
6 ms |
384 KB |
Output is correct |
13 |
Correct |
100 ms |
4488 KB |
Output is correct |
14 |
Correct |
113 ms |
5240 KB |
Output is correct |
15 |
Correct |
108 ms |
5240 KB |
Output is correct |
16 |
Correct |
106 ms |
5240 KB |
Output is correct |
17 |
Correct |
96 ms |
5200 KB |
Output is correct |
18 |
Correct |
101 ms |
5240 KB |
Output is correct |
19 |
Correct |
101 ms |
5240 KB |
Output is correct |
20 |
Correct |
117 ms |
5240 KB |
Output is correct |
21 |
Correct |
105 ms |
5296 KB |
Output is correct |
22 |
Correct |
102 ms |
5240 KB |
Output is correct |
23 |
Correct |
152 ms |
5624 KB |
Output is correct |
24 |
Correct |
140 ms |
6520 KB |
Output is correct |
25 |
Correct |
152 ms |
6392 KB |
Output is correct |
26 |
Correct |
131 ms |
6392 KB |
Output is correct |
27 |
Correct |
144 ms |
6520 KB |
Output is correct |
28 |
Correct |
138 ms |
6392 KB |
Output is correct |
29 |
Correct |
148 ms |
6392 KB |
Output is correct |
30 |
Correct |
130 ms |
6392 KB |
Output is correct |
31 |
Correct |
144 ms |
6392 KB |
Output is correct |
32 |
Correct |
157 ms |
6392 KB |
Output is correct |
33 |
Correct |
145 ms |
6392 KB |
Output is correct |
34 |
Correct |
135 ms |
6392 KB |
Output is correct |
35 |
Correct |
142 ms |
6392 KB |
Output is correct |
36 |
Correct |
139 ms |
6392 KB |
Output is correct |
37 |
Correct |
144 ms |
6264 KB |
Output is correct |
38 |
Correct |
281 ms |
6752 KB |
Output is correct |
39 |
Correct |
168 ms |
6520 KB |
Output is correct |
40 |
Correct |
280 ms |
6648 KB |
Output is correct |
41 |
Correct |
185 ms |
6520 KB |
Output is correct |
42 |
Correct |
199 ms |
6648 KB |
Output is correct |
43 |
Correct |
275 ms |
6636 KB |
Output is correct |
44 |
Correct |
178 ms |
6452 KB |
Output is correct |
45 |
Correct |
230 ms |
6632 KB |
Output is correct |
46 |
Correct |
169 ms |
6648 KB |
Output is correct |
47 |
Correct |
192 ms |
6520 KB |
Output is correct |
48 |
Correct |
187 ms |
6520 KB |
Output is correct |
49 |
Correct |
192 ms |
6520 KB |
Output is correct |
50 |
Correct |
159 ms |
6520 KB |
Output is correct |
51 |
Correct |
194 ms |
6476 KB |
Output is correct |
52 |
Correct |
261 ms |
6776 KB |
Output is correct |
53 |
Correct |
178 ms |
6556 KB |
Output is correct |
54 |
Correct |
196 ms |
6520 KB |
Output is correct |
55 |
Correct |
218 ms |
6520 KB |
Output is correct |
56 |
Correct |
193 ms |
6520 KB |
Output is correct |
57 |
Correct |
180 ms |
6520 KB |
Output is correct |
58 |
Correct |
228 ms |
6520 KB |
Output is correct |