This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |