답안 #916991

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
916991 2024-01-26T22:58:59 Z MilosMilutinovic 청소 (JOI20_sweeping) C++14
100 / 100
10736 ms 356036 KB
#include<bits/stdc++.h>
 
#define pb push_back
#define fi first
#define se second
#define mp make_pair
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
 
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
 
ll readint(){
	ll x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n,m,q;
int v[2000005][2],fa[2000005],ch[2000005][2],tag[2000005][2],prior[2000005];
mt19937 rng(time(0));
 
void make(int id){ tag[id][0]=tag[id][1]=-1; prior[id]=rng(); fa[id]=ch[id][0]=ch[id][1]=0; }
 
void pushdown(int id){
	if(!id) return;
	for(int i=0;i<2;i++){
		if(tag[id][i]==-1) continue;
		for(int j=0;j<2;j++){
			if(ch[id][j]==0) continue;
			v[ch[id][j]][i]=tag[id][i];
			tag[ch[id][j]][i]=tag[id][i];
		}
		tag[id][i]=-1;
	}
}
 
void split(int id,int&l,int&r,int a,int b,int idx){
	if(!id) return (void)(l=r=0);
	pushdown(id);
	if(v[id][0]<=a&&v[id][1]<=b&&(mp(v[id][0],v[id][1])!=mp(a,b)||id<idx)){
		fa[ch[id][1]]=0;
		split(ch[id][1],ch[id][1],r,a,b,idx);
		l=id; 
		fa[ch[id][1]]=id;
	}else{
		fa[ch[id][0]]=0;
		split(ch[id][0],l,ch[id][0],a,b,idx);
		r=id;  
		fa[ch[id][0]]=id;
	}
}
 
void merge(int&id,int l,int r){
	if(!l) return (void)(id=r);
	if(!r) return (void)(id=l);
	pushdown(l);
	pushdown(r);
	if(prior[l]>prior[r]) swap(l,r);
	int L=0,R=0;
	split(l,L,R,v[r][0],v[r][1],r);
	fa[ch[r][0]]=0;
	fa[ch[r][1]]=0;
	merge(ch[r][0],ch[r][0],L);
	merge(ch[r][1],ch[r][1],R);
	fa[ch[r][0]]=r;
	fa[ch[r][1]]=r;
	id=r;
	pushdown(id);
}

namespace segtree{
	int root,tsz,ls[30000005],rs[30000005];
	map<int,multiset<pii>> ids;
	pii mini[30000005];
	void modify(int&id,int l,int r,int i,pii v){
		if(!id) id=++tsz,mini[id]=mp(n+1,0);
		if(l==r) return (void)(mini[id]=v);
		int mid=(l+r)/2;
		if(i<=mid) modify(ls[id],l,mid,i,v);
		else modify(rs[id],mid+1,r,i,v);
		mini[id]=mp(n+1,0);
		if(ls[id]) mini[id]=min(mini[id],mini[ls[id]]);
		if(rs[id]) mini[id]=min(mini[id],mini[rs[id]]);
	}
	pii query(int id,int l,int r,int ql,int qr){
		if(!id||l>r||l>qr||r<ql) return mp(n+1,0);
		if(ql<=l&&r<=qr) return mini[id];
		int mid=(l+r)/2;
		return min(query(ls[id],l,mid,ql,qr),query(rs[id],mid+1,r,ql,qr));
	}
	void add(int x,int y,int i){
		ids[x].emplace(y,i);
		modify(root,0,n,x,*ids[x].begin());
	}
	void rem(int x,int y,int i){
		if(ids[x].find(mp(y,i))==ids[x].end()) while(true){}
		ids[x].erase(ids[x].find(mp(y,i)));
		modify(root,0,n,x,(ids[x].empty()?mp(n+1,0):*ids[x].begin()));
	}
	pii get(int l,int r){ return query(root,0,n,l,r); }
};

vector<int> find(int l){
	vector<int> ret;
	while(true){
		pii mn=segtree::get(0,l);
		if(mn.fi>n-l) break;
		int i=mn.se;
		segtree::rem(v[i][0],v[i][1],i);
		while(fa[i]) i=fa[i];
		ret.pb(i);
	}
	return ret;
}

int godown(int id){
	if(!ch[id][0]) return id;
	else return godown(ch[id][0]);
}
 
int main(){
	n=readint();
	m=readint();
	q=readint();
	for(int i=1;i<=m;i++) for(int j=0;j<2;j++) v[i][j]=readint();
	for(int i=1;i<=m;i++) make(i),segtree::add(v[i][0],v[i][1],i);
	while(q--){
		int t=readint();
		if(t==1){
			int i=readint();
			vector<int> anc;
			for(int v=i;v;v=fa[v]) anc.pb(v);
			reverse(anc.begin(),anc.end());
			for(int v:anc) pushdown(v);
			printf("%d %d\n",v[i][0],v[i][1]);
		}
		if(t==2){
			int l=readint();
			int root=0;
			vector<int> ids=find(n-l);
			for(int i:ids){
				int L=0,R=0;
				split(i,L,R,n-l,l,1e9);
				if(R!=0){
					int x=godown(R);
					vector<int> anc;
					for(int v=x;v;v=fa[v]) anc.pb(v);
					reverse(anc.begin(),anc.end());
					for(int v:anc) pushdown(v);
					segtree::add(v[x][0],v[x][1],x);
				}
				v[L][0]=n-l;
				tag[L][0]=n-l;
				pushdown(L);
				merge(root,root,L);
				pushdown(root);
			}
			if(root!=0){
				int x=godown(root);
				vector<int> anc;
				for(int v=x;v;v=fa[v]) anc.pb(v);
				reverse(anc.begin(),anc.end());
				for(int v:anc) pushdown(v);
				segtree::add(v[x][0],v[x][1],x);
			}
		}
		if(t==3){
			int l=readint();
			int root=0;
			vector<int> ids=find(l);
			for(int i:ids){
				int L=0,R=0;
				split(i,L,R,l,n-l,1e9);				
				if(R!=0){
					int x=godown(R);
					vector<int> anc;
					for(int v=x;v;v=fa[v]) anc.pb(v);
					reverse(anc.begin(),anc.end());
					for(int v:anc) pushdown(v);
					segtree::add(v[x][0],v[x][1],x);
				}
				v[L][1]=n-l;
				tag[L][1]=n-l;
				pushdown(L);
				pushdown(R);
				merge(root,root,L);
				pushdown(root);
			}
			if(root!=0){
				int x=godown(root);
				vector<int> anc;
				for(int v=x;v;v=fa[v]) anc.pb(v);
				reverse(anc.begin(),anc.end());
				for(int v:anc) pushdown(v);
				segtree::add(v[x][0],v[x][1],x);
			}
		}
		if(t==4){
			make(++m);
			for(int j=0;j<2;j++) v[m][j]=readint();
			segtree::add(v[m][0],v[m][1],m);	
		}
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 15452 KB Output is correct
2 Correct 9 ms 15284 KB Output is correct
3 Correct 6 ms 15460 KB Output is correct
4 Correct 12 ms 15452 KB Output is correct
5 Correct 12 ms 12960 KB Output is correct
6 Correct 5 ms 12636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7882 ms 323212 KB Output is correct
2 Correct 7672 ms 341828 KB Output is correct
3 Correct 7749 ms 342292 KB Output is correct
4 Correct 5236 ms 308868 KB Output is correct
5 Correct 5497 ms 346088 KB Output is correct
6 Correct 7919 ms 325184 KB Output is correct
7 Correct 7597 ms 339136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2735 ms 221344 KB Output is correct
2 Correct 2267 ms 206428 KB Output is correct
3 Correct 1529 ms 220752 KB Output is correct
4 Correct 2824 ms 254200 KB Output is correct
5 Correct 2305 ms 204088 KB Output is correct
6 Correct 2069 ms 205600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2735 ms 221344 KB Output is correct
2 Correct 2267 ms 206428 KB Output is correct
3 Correct 1529 ms 220752 KB Output is correct
4 Correct 2824 ms 254200 KB Output is correct
5 Correct 2305 ms 204088 KB Output is correct
6 Correct 2069 ms 205600 KB Output is correct
7 Correct 5239 ms 228164 KB Output is correct
8 Correct 5298 ms 228128 KB Output is correct
9 Correct 5240 ms 228432 KB Output is correct
10 Correct 4192 ms 228120 KB Output is correct
11 Correct 6860 ms 254036 KB Output is correct
12 Correct 5339 ms 203788 KB Output is correct
13 Correct 5442 ms 207904 KB Output is correct
14 Correct 109 ms 12636 KB Output is correct
15 Correct 895 ms 75852 KB Output is correct
16 Correct 5308 ms 245412 KB Output is correct
17 Correct 4583 ms 226208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 15452 KB Output is correct
2 Correct 9 ms 15284 KB Output is correct
3 Correct 6 ms 15460 KB Output is correct
4 Correct 12 ms 15452 KB Output is correct
5 Correct 12 ms 12960 KB Output is correct
6 Correct 5 ms 12636 KB Output is correct
7 Correct 7882 ms 323212 KB Output is correct
8 Correct 7672 ms 341828 KB Output is correct
9 Correct 7749 ms 342292 KB Output is correct
10 Correct 5236 ms 308868 KB Output is correct
11 Correct 5497 ms 346088 KB Output is correct
12 Correct 7919 ms 325184 KB Output is correct
13 Correct 7597 ms 339136 KB Output is correct
14 Correct 2735 ms 221344 KB Output is correct
15 Correct 2267 ms 206428 KB Output is correct
16 Correct 1529 ms 220752 KB Output is correct
17 Correct 2824 ms 254200 KB Output is correct
18 Correct 2305 ms 204088 KB Output is correct
19 Correct 2069 ms 205600 KB Output is correct
20 Correct 5239 ms 228164 KB Output is correct
21 Correct 5298 ms 228128 KB Output is correct
22 Correct 5240 ms 228432 KB Output is correct
23 Correct 4192 ms 228120 KB Output is correct
24 Correct 6860 ms 254036 KB Output is correct
25 Correct 5339 ms 203788 KB Output is correct
26 Correct 5442 ms 207904 KB Output is correct
27 Correct 109 ms 12636 KB Output is correct
28 Correct 895 ms 75852 KB Output is correct
29 Correct 5308 ms 245412 KB Output is correct
30 Correct 4583 ms 226208 KB Output is correct
31 Correct 4881 ms 268824 KB Output is correct
32 Correct 7145 ms 273404 KB Output is correct
33 Correct 2701 ms 258700 KB Output is correct
34 Correct 10711 ms 355716 KB Output is correct
35 Correct 10736 ms 356036 KB Output is correct
36 Correct 5145 ms 276632 KB Output is correct
37 Correct 9149 ms 328916 KB Output is correct
38 Correct 8961 ms 310052 KB Output is correct
39 Correct 8256 ms 287868 KB Output is correct
40 Correct 6712 ms 288392 KB Output is correct