#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[100010];
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 |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
6 ms |
512 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
6 ms |
384 KB |
Output is correct |
12 |
Correct |
6 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
6 ms |
512 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
6 ms |
384 KB |
Output is correct |
12 |
Correct |
6 ms |
512 KB |
Output is correct |
13 |
Runtime error |
22 ms |
2048 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
25 ms |
2176 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
6 ms |
512 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
6 ms |
384 KB |
Output is correct |
12 |
Correct |
6 ms |
512 KB |
Output is correct |
13 |
Runtime error |
22 ms |
2048 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
14 |
Halted |
0 ms |
0 KB |
- |