답안 #290136

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
290136 2020-09-03T12:31:39 Z TadijaSebez 청소 (JOI20_sweeping) C++11
100 / 100
4788 ms 603636 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int,int>
struct Query{
	int type;
	int idx,x,y;
	int l;
	Query(){}
	Query(int t,int i,int X,int Y):type(t),idx(i),x(X),y(Y),l(-1){}
	Query(int t,int i,int L):type(t),idx(i),l(L),x(-1),y(-1){}
};
const int N=1500050;
const int M=2*N;
pii ans[N];
int n,m,q;
int val[M],myc[N*2],tsz,rem[N];
vector<int> cmp[M];
int add(int i,int v){tsz++;val[tsz]=v;myc[i]=tsz;cmp[tsz]={i};return tsz;}
int mrg(int a,int b){
	if(cmp[a].size()>cmp[b].size())swap(a,b);
	for(int i:cmp[a]){
		myc[i]=b;
		cmp[b].pb(i);
	}
	cmp[a].clear();
	return b;
}
void DNC(int l,int r,vector<Query> Qs){
	if(Qs.empty())return;
	int mid=l+r>>1;
	int X=mid,Y=n-mid;
	priority_queue<pii> xs,ys;
	vector<Query> LQ,RQ;
	for(Query qu:Qs){
		if(qu.type==1){
			int x=val[myc[qu.idx<<1]],y=val[myc[qu.idx<<1|1]];
			if(rem[qu.idx]==1)RQ.pb(qu);
			else if(rem[qu.idx]==2)LQ.pb(qu);
			else ans[qu.l]={x,y};
		}else if(qu.type==2){
			if(qu.l<Y){
				RQ.pb(qu);
				while(ys.size()&&-ys.top().first<=qu.l){
					int c=ys.top().second;
					ys.pop();
					for(int i:cmp[c])if(!rem[i/2]){
						int x=n-qu.l,y=val[c];
						RQ.pb(Query(4,i/2,x,y));
						rem[i/2]=1;
					}
				}
			}else{
				int now=0;
				while(xs.size()&&-xs.top().first<n-qu.l){
					int tmp=xs.top().second;
					xs.pop();
					now=now?mrg(now,tmp):tmp;
				}
				if(now)val[now]=n-qu.l,xs.push({-val[now],now});
				LQ.pb(qu);
			}
		}else if(qu.type==3){
			if(qu.l<X){
				LQ.pb(qu);
				while(xs.size()&&-xs.top().first<=qu.l){
					int c=xs.top().second;
					xs.pop();
					for(int i:cmp[c])if(!rem[i/2]){
						int x=val[c],y=n-qu.l;
						LQ.pb(Query(4,i/2,x,y));
						rem[i/2]=2;
					}
				}
			}else{
				int now=0;
				while(ys.size()&&-ys.top().first<n-qu.l){
					int tmp=ys.top().second;
					ys.pop();
					now=now?mrg(now,tmp):tmp;
				}
				if(now)val[now]=n-qu.l,ys.push({-val[now],now});
				RQ.pb(qu);
			}
		}else{
			if(qu.x>X)rem[qu.idx]=1,RQ.pb(qu);
			else if(qu.y>Y)rem[qu.idx]=2,LQ.pb(qu);
			else{
				rem[qu.idx]=0;
				xs.push({-qu.x,add(qu.idx<<1,qu.x)});
				ys.push({-qu.y,add(qu.idx<<1|1,qu.y)});
			}
		}
	}
	tsz=0;
	if(l==r)return;
	if(l+1==r)DNC(r,r,RQ);
	else{
		DNC(l,mid,LQ);
		DNC(mid,r,RQ);
	}
}
int main(){
	scanf("%i %i %i",&n,&m,&q);
	vector<Query> Qs;
	for(int i=1,x,y;i<=m;i++){
		scanf("%i %i",&x,&y);
		Qs.pb(Query(4,i,x,y));
	}
	int z=0;
	for(int i=1;i<=q;i++){
		int t;scanf("%i",&t);
		if(t==1){
			int idx;scanf("%i",&idx);
			Qs.pb(Query(1,idx,++z));
		}else if(t==2||t==3){
			int l;scanf("%i",&l);
			Qs.pb(Query(t,-1,l));
		}else{
			int x,y;scanf("%i %i",&x,&y);
			Qs.pb(Query(4,++m,x,y));
		}
	}
	DNC(0,n,Qs);
	for(int i=1;i<=z;i++)printf("%i %i\n",ans[i].first,ans[i].second);
	return 0;
}

Compilation message

sweeping.cpp: In constructor 'Query::Query(int, int, int)':
sweeping.cpp:8:6: warning: 'Query::l' will be initialized after [-Wreorder]
    8 |  int l;
      |      ^
sweeping.cpp:7:10: warning:   'int Query::x' [-Wreorder]
    7 |  int idx,x,y;
      |          ^
sweeping.cpp:11:2: warning:   when initialized here [-Wreorder]
   11 |  Query(int t,int i,int L):type(t),idx(i),l(L),x(-1),y(-1){}
      |  ^~~~~
sweeping.cpp: In function 'void DNC(int, int, std::vector<Query>)':
sweeping.cpp:31:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   31 |  int mid=l+r>>1;
      |          ~^~
sweeping.cpp: In function 'int main()':
sweeping.cpp:104:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  104 |  scanf("%i %i %i",&n,&m,&q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~
sweeping.cpp:107:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  107 |   scanf("%i %i",&x,&y);
      |   ~~~~~^~~~~~~~~~~~~~~
sweeping.cpp:112:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  112 |   int t;scanf("%i",&t);
      |         ~~~~~^~~~~~~~~
sweeping.cpp:114:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  114 |    int idx;scanf("%i",&idx);
      |            ~~~~~^~~~~~~~~~~
sweeping.cpp:117:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  117 |    int l;scanf("%i",&l);
      |          ~~~~~^~~~~~~~~
sweeping.cpp:120:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  120 |    int x,y;scanf("%i %i",&x,&y);
      |            ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 72080 KB Output is correct
2 Correct 56 ms 71512 KB Output is correct
3 Correct 55 ms 71512 KB Output is correct
4 Correct 65 ms 72052 KB Output is correct
5 Correct 58 ms 71952 KB Output is correct
6 Correct 51 ms 71808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3347 ms 258628 KB Output is correct
2 Correct 3325 ms 270600 KB Output is correct
3 Correct 3280 ms 271984 KB Output is correct
4 Correct 2767 ms 374704 KB Output is correct
5 Correct 3989 ms 314244 KB Output is correct
6 Correct 3673 ms 341244 KB Output is correct
7 Correct 3137 ms 269064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2941 ms 303292 KB Output is correct
2 Correct 2950 ms 337036 KB Output is correct
3 Correct 2452 ms 348632 KB Output is correct
4 Correct 3105 ms 495620 KB Output is correct
5 Correct 3034 ms 431688 KB Output is correct
6 Correct 2735 ms 331912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2941 ms 303292 KB Output is correct
2 Correct 2950 ms 337036 KB Output is correct
3 Correct 2452 ms 348632 KB Output is correct
4 Correct 3105 ms 495620 KB Output is correct
5 Correct 3034 ms 431688 KB Output is correct
6 Correct 2735 ms 331912 KB Output is correct
7 Correct 3337 ms 296616 KB Output is correct
8 Correct 3281 ms 307292 KB Output is correct
9 Correct 3378 ms 290624 KB Output is correct
10 Correct 3063 ms 346592 KB Output is correct
11 Correct 3807 ms 433048 KB Output is correct
12 Correct 4219 ms 376792 KB Output is correct
13 Correct 4347 ms 572988 KB Output is correct
14 Correct 406 ms 183820 KB Output is correct
15 Correct 1044 ms 218120 KB Output is correct
16 Correct 3152 ms 305676 KB Output is correct
17 Correct 3096 ms 304616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 72080 KB Output is correct
2 Correct 56 ms 71512 KB Output is correct
3 Correct 55 ms 71512 KB Output is correct
4 Correct 65 ms 72052 KB Output is correct
5 Correct 58 ms 71952 KB Output is correct
6 Correct 51 ms 71808 KB Output is correct
7 Correct 3347 ms 258628 KB Output is correct
8 Correct 3325 ms 270600 KB Output is correct
9 Correct 3280 ms 271984 KB Output is correct
10 Correct 2767 ms 374704 KB Output is correct
11 Correct 3989 ms 314244 KB Output is correct
12 Correct 3673 ms 341244 KB Output is correct
13 Correct 3137 ms 269064 KB Output is correct
14 Correct 2941 ms 303292 KB Output is correct
15 Correct 2950 ms 337036 KB Output is correct
16 Correct 2452 ms 348632 KB Output is correct
17 Correct 3105 ms 495620 KB Output is correct
18 Correct 3034 ms 431688 KB Output is correct
19 Correct 2735 ms 331912 KB Output is correct
20 Correct 3337 ms 296616 KB Output is correct
21 Correct 3281 ms 307292 KB Output is correct
22 Correct 3378 ms 290624 KB Output is correct
23 Correct 3063 ms 346592 KB Output is correct
24 Correct 3807 ms 433048 KB Output is correct
25 Correct 4219 ms 376792 KB Output is correct
26 Correct 4347 ms 572988 KB Output is correct
27 Correct 406 ms 183820 KB Output is correct
28 Correct 1044 ms 218120 KB Output is correct
29 Correct 3152 ms 305676 KB Output is correct
30 Correct 3096 ms 304616 KB Output is correct
31 Correct 3060 ms 346228 KB Output is correct
32 Correct 3753 ms 283784 KB Output is correct
33 Correct 3367 ms 259720 KB Output is correct
34 Correct 3510 ms 311388 KB Output is correct
35 Correct 3405 ms 297088 KB Output is correct
36 Correct 2927 ms 346048 KB Output is correct
37 Correct 4788 ms 567944 KB Output is correct
38 Correct 4370 ms 603636 KB Output is correct
39 Correct 3876 ms 524424 KB Output is correct
40 Correct 3145 ms 312020 KB Output is correct