답안 #382089

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
382089 2021-03-26T11:28:20 Z kshitij_sodani Tenis (COI19_tenis) C++14
100 / 100
358 ms 8060 KB
//#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){
	push(no,l,r);
	/*if(r<aa or l>bb){
		return 0;
	}*/
	if(tree[no]<n){
		return -1;
	}
	if(l==r){
		return l;
	}
	
	//else{
		int mid=(l+r)/2;
		int x=query(no*2+1,l,mid);
		push(no*2+2,mid+1,r);
		tree[no]=max(tree[no*2+1],tree[no*2+2]);
		if(x!=-1){
			return x;
		}
		int y=query(no*2+2,mid+1,r);
		return y;
/*
		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;*/
			int low=query(0,0,n-1);
			//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:160:8: warning: unused variable 'ind2' [-Wunused-variable]
  160 |    int ind2=ind[y][x];
      |        ^~~~
tenis.cpp:161:8: warning: unused variable 'ind3' [-Wunused-variable]
  161 |    int ind3=ind[z][x];
      |        ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 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 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 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 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 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 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 113 ms 5048 KB Output is correct
14 Correct 109 ms 4844 KB Output is correct
15 Correct 106 ms 4716 KB Output is correct
16 Correct 111 ms 4716 KB Output is correct
17 Correct 116 ms 4844 KB Output is correct
18 Correct 108 ms 4716 KB Output is correct
19 Correct 106 ms 4844 KB Output is correct
20 Correct 108 ms 4844 KB Output is correct
21 Correct 108 ms 4716 KB Output is correct
22 Correct 105 ms 4716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 169 ms 5100 KB Output is correct
2 Correct 167 ms 7532 KB Output is correct
3 Correct 162 ms 7532 KB Output is correct
4 Correct 165 ms 7532 KB Output is correct
5 Correct 159 ms 7532 KB Output is correct
6 Correct 162 ms 7624 KB Output is correct
7 Correct 162 ms 7532 KB Output is correct
8 Correct 169 ms 7532 KB Output is correct
9 Correct 163 ms 7496 KB Output is correct
10 Correct 161 ms 7564 KB Output is correct
11 Correct 166 ms 7532 KB Output is correct
12 Correct 159 ms 7532 KB Output is correct
13 Correct 165 ms 7532 KB Output is correct
14 Correct 165 ms 7532 KB Output is correct
15 Correct 164 ms 7532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 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 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 113 ms 5048 KB Output is correct
14 Correct 109 ms 4844 KB Output is correct
15 Correct 106 ms 4716 KB Output is correct
16 Correct 111 ms 4716 KB Output is correct
17 Correct 116 ms 4844 KB Output is correct
18 Correct 108 ms 4716 KB Output is correct
19 Correct 106 ms 4844 KB Output is correct
20 Correct 108 ms 4844 KB Output is correct
21 Correct 108 ms 4716 KB Output is correct
22 Correct 105 ms 4716 KB Output is correct
23 Correct 169 ms 5100 KB Output is correct
24 Correct 167 ms 7532 KB Output is correct
25 Correct 162 ms 7532 KB Output is correct
26 Correct 165 ms 7532 KB Output is correct
27 Correct 159 ms 7532 KB Output is correct
28 Correct 162 ms 7624 KB Output is correct
29 Correct 162 ms 7532 KB Output is correct
30 Correct 169 ms 7532 KB Output is correct
31 Correct 163 ms 7496 KB Output is correct
32 Correct 161 ms 7564 KB Output is correct
33 Correct 166 ms 7532 KB Output is correct
34 Correct 159 ms 7532 KB Output is correct
35 Correct 165 ms 7532 KB Output is correct
36 Correct 165 ms 7532 KB Output is correct
37 Correct 164 ms 7532 KB Output is correct
38 Correct 358 ms 7788 KB Output is correct
39 Correct 212 ms 7660 KB Output is correct
40 Correct 345 ms 7916 KB Output is correct
41 Correct 236 ms 7660 KB Output is correct
42 Correct 248 ms 7788 KB Output is correct
43 Correct 344 ms 8060 KB Output is correct
44 Correct 208 ms 7668 KB Output is correct
45 Correct 258 ms 7660 KB Output is correct
46 Correct 214 ms 7660 KB Output is correct
47 Correct 237 ms 7788 KB Output is correct
48 Correct 218 ms 7660 KB Output is correct
49 Correct 255 ms 7788 KB Output is correct
50 Correct 203 ms 7660 KB Output is correct
51 Correct 242 ms 7788 KB Output is correct
52 Correct 344 ms 7916 KB Output is correct
53 Correct 243 ms 7788 KB Output is correct
54 Correct 247 ms 7660 KB Output is correct
55 Correct 245 ms 7660 KB Output is correct
56 Correct 253 ms 7788 KB Output is correct
57 Correct 224 ms 7716 KB Output is correct
58 Correct 258 ms 7788 KB Output is correct