QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#1205#758449#9559. The TowerLinkWishucup-team5319Success!2024-11-20 08:40:492024-11-20 08:40:53

Details

Extra Test:

Time Limit Exceeded

input:

500000
1 96336
1 86820
2 1
1 68930
1 12453
1 28646
2 5
1 94342
2 6
2 3
1 30613
1 48555
1 82630
1 13293
2 7
1 72427
1 4991
1 17091
1 14830
1 73769
2 10
1 24904
2 15
2 16
1 5793
2 13
1 57290
1 12794
2 8
1 28559
2 11
2 12
1 71879
2 9
2 20
2 4
1 22485
2 17
1 44695
2 18
2 23
2 21
2 14
2 22
1 32069
1 6007...

output:


result:


IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#758449#9559. The Towerucup-team5319TL 1723ms420592kbC++142.5kb2024-11-17 18:22:052024-11-20 08:56:10

answer

//Linkwish's code
#include<bits/stdc++.h>
#define endl '\n'
#define si inline
#define fi first
#define se second
using namespace std;
typedef long long ll;typedef __int128 li;typedef long double ld;
typedef pair<int,int> pii;typedef pair<ll,ll> pll;
typedef const int ci;typedef const ll cl;ci iinf=INT_MAX;cl linf=LLONG_MAX;
template<typename T>si bool gmax(T &x,const T y){if(x<y)return x=y,1;return 0;}
template<typename T>si bool gmin(T &x,const T y){if(y<x)return x=y,1;return 0;}

namespace LinkWish{
	
	ci N=500005,lim=1e9;

	vector<pii> p[N];

	int n;

	struct Hoshino{
		int ls,rs,tag,emp;
	}t[N*30];
	int rt,cnt;
	si int np(int len){
		cnt++,t[cnt].emp=len;
		t[cnt].ls=t[cnt].rs=0,t[cnt].tag=-1;
		return cnt;
	}
	si void push_up(int x){t[x].emp=t[t[x].ls].emp+t[t[x].rs].emp;}
	si void update(int x,int col){
		p[col].emplace_back(x,t[x].emp);
		t[x].emp=0,t[x].tag=col;
	}
	si void push_down(int x){
		if(~t[x].tag){
			if(t[t[x].ls].emp!=0)update(t[x].ls,t[x].tag);
			if(t[t[x].rs].emp!=0)update(t[x].rs,t[x].tag);
			t[x].tag=-1;
		}
	}
	void modify(int &x,int l,int r,int c,int &k){
		if(t[x].emp==0)return ;
		if(k>=t[x].emp)return k-=t[x].emp,update(x,c),void();
		p[c].emplace_back(x,0);
		int mid=(l+r)>>1;
		if(t[x].ls==0)t[x].ls=np(mid-l+1);
		if(t[x].rs==0)t[x].rs=np(r-mid);
		push_down(x);
		modify(t[x].ls,l,mid,c,k);
		if(k>0)modify(t[x].rs,mid+1,r,c,k);
		push_up(x);
	}
	int ask(int x,int l,int r,int goal){
		if(l==r)return t[x].tag;
		int mid=(l+r)>>1;
		if(t[x].ls==0||t[x].rs==0)return t[x].tag;
		push_down(x);
		if(goal<=mid)return ask(t[x].ls,l,mid,goal);
		return ask(t[x].rs,mid+1,r,goal);
	}

	int tot;
	si void ins(int k){
		tot++;
		modify(rt,1,lim,tot,k);
	}
	int ct;
	si void era(int id){
		vector<int> tmp;
		for(pii i:p[id]){
			int x=i.fi,v=i.se;
			if(t[x].tag==id)t[x].emp=v,t[x].tag=-1;
			else push_down(x),tmp.push_back(x);
		}
		for(auto it=tmp.rbegin();it!=tmp.rend();it++)push_up(*it);
		p[id].clear(),p[id].shrink_to_fit();
	}

	si void solve(){
		cin>>n;

		rt=np(lim);

		while(n--){
			int op,x;cin>>op>>x;
			if(op==1)ins(x);
			else if(op==2)era(x);
			else{
				int res=ask(rt,1,lim,x);
				if(res==-1)cout<<"0\n";
				else cout<<res<<endl;
			}
		}
	}

	void mian(){
		solve();
	}
}

signed main(){
	#ifndef ONLINE_JUDGE
	assert(freopen("in.in","r",stdin));
	assert(freopen("out.out","w",stdout));
	#endif
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	LinkWish::mian();
	return 0;
}