//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#define endl '\n'
int n,q;
int it[100001][3];
int vis[100001][3];
int tree[100001*4];
int lazy[100001*4];
int ind[100001][3];
void push(int no,int l,int r){
tree[no]+=lazy[no];
if(l<r){
lazy[no*2+1]+=lazy[no];
lazy[no*2+2]+=lazy[no];
}
lazy[no]=0;
}
void update(int no,int l,int r,int aa,int bb,int val){
push(no,l,r);
if(r<aa or l>bb){
return;
}
if(aa<=l and r<=bb){
lazy[no]+=val;
push(no,l,r);
}
else{
int mid=(l+r)/2;
update(no*2+1,l,mid,aa,bb,val);
update(no*2+2,mid+1,r,aa,bb,val);
tree[no]=max(tree[no*2+1],tree[no*2+2]);
}
}
int query(int no,int l,int r,int aa,int bb){
push(no,l,r);
if(r<aa or l>bb){
return 0;
}
if(aa<=l and r<=bb){
return tree[no];
}
else{
int mid=(l+r)/2;
int x=max(query(no*2+1,l,mid,aa,bb),query(no*2+2,mid+1,r,aa,bb));
tree[no]=max(tree[no*2+1],tree[no*2+2]);
return x;
}
}
void pro(int i,int val=1){
int x=min(ind[i][0],ind[i][1]);
x=min(x,ind[i][2]);
if(x>0){
update(0,0,n-1,0,x-1,val);
}
x=max(max(ind[i][0],ind[i][1]),ind[i][2]);
update(0,0,n-1,x,n-1,val);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>q;
for(int i=0;i<n;i++){
cin>>it[i][0];
ind[it[i][0]][0]=i;
}
for(int i=0;i<n;i++){
cin>>it[i][1];
ind[it[i][1]][1]=i;
}
for(int i=0;i<n;i++){
cin>>it[i][2];
ind[it[i][2]][2]=i;
}
for(int i=0;i<n;i++){
pro(i+1,1);
}
while(q--){
int tt;
cin>>tt;
if(tt==1){
int x;
cin>>x;
int low=-1;
/* for(int i=0;i<n;i++){
cout<<query(0,0,n-1,0,i)<<":";
}
cout<<endl;*/
for(int j=19;j>=0;j--){
if((1<<j)+low<n){
if(query(0,0,n-1,0,(1<<j)+low)<n){
low+=(1<<j);
}
}
}
low+=1;
if(ind[x][0]>low){
cout<<"NE"<<endl;
}
else{
cout<<"DA"<<endl;
}
/*int st=0;
for(int i=1;i<=n;i++){
for(int j=0;j<3;j++){
vis[i][j]=0;
}
}
set<int> ss;
for(int i=0;i<n;i++){
int kk=1;
for(int j=0;j<3;j++){
ss.erase(it[i][j]);
vis[it[i][j]][j]=1;
if(vis[it[i][j]][0]!=vis[it[i][j]][1] or vis[it[i][j]][0]!=vis[it[i][j]][2]){
ss.insert(it[i][j]);
continue;
}
}
if(vis[x][0]+vis[x][1]+vis[x][2]>0){
kk=0;
break;
}
if(ss.size()==0){
st=1;
break;
}
}*/
/*if(st==0){
cout<<"DA"<<endl;
}
else{
cout<<"NE"<<endl;
}*/
}
else{
int x,y,z;
cin>>x>>y>>z;
x--;
pro(y,-1);
pro(z,-1);
int ind2=ind[y][x];
int ind3=ind[z][x];
swap(ind[y][x],ind[z][x]);
pro(y,1);
pro(z,1);
/*for(int i=0;i<n;i++){
if(it[i][x]==y){
ind=i;
}
if(it[i][x]==z){
ind2=i;
}
}*/
//cout<<ind<<":"<<ind2<<endl;
//swap(it[ind][x],it[ind2][x]);
}
}
return 0;
}
Compilation message
tenis.cpp: In function 'int main()':
tenis.cpp:153:8: warning: unused variable 'ind2' [-Wunused-variable]
153 | int ind2=ind[y][x];
| ^~~~
tenis.cpp:154:8: warning: unused variable 'ind3' [-Wunused-variable]
154 | int ind3=ind[z][x];
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
376 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
376 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
2 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 |
2 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
376 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
2 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 |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
120 ms |
4716 KB |
Output is correct |
14 |
Correct |
113 ms |
4716 KB |
Output is correct |
15 |
Correct |
109 ms |
4844 KB |
Output is correct |
16 |
Correct |
131 ms |
4844 KB |
Output is correct |
17 |
Correct |
111 ms |
4716 KB |
Output is correct |
18 |
Correct |
107 ms |
4716 KB |
Output is correct |
19 |
Correct |
106 ms |
4716 KB |
Output is correct |
20 |
Correct |
107 ms |
4716 KB |
Output is correct |
21 |
Correct |
110 ms |
4844 KB |
Output is correct |
22 |
Correct |
121 ms |
4844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
689 ms |
5704 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
376 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
2 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 |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
120 ms |
4716 KB |
Output is correct |
14 |
Correct |
113 ms |
4716 KB |
Output is correct |
15 |
Correct |
109 ms |
4844 KB |
Output is correct |
16 |
Correct |
131 ms |
4844 KB |
Output is correct |
17 |
Correct |
111 ms |
4716 KB |
Output is correct |
18 |
Correct |
107 ms |
4716 KB |
Output is correct |
19 |
Correct |
106 ms |
4716 KB |
Output is correct |
20 |
Correct |
107 ms |
4716 KB |
Output is correct |
21 |
Correct |
110 ms |
4844 KB |
Output is correct |
22 |
Correct |
121 ms |
4844 KB |
Output is correct |
23 |
Execution timed out |
689 ms |
5704 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |