이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
priority_queue<int> bruh[300005],del[300005];
int cnum;
struct node{
	int s,e,m;
	int val,pnum;
	node *l, *r;
	node(int S, int E){
		s=S; e=E; m=(s+e)/2;
		val=0;
		l=r=NULL;
		if(s==e){
			pnum=cnum;
			cnum++;
		}
	}
	
	void update(int S, int V, int R){
		if(s==e){
			if(R!=-1) del[pnum].push(R);
			if(V!=-1) bruh[pnum].push(V);
			while(!del[pnum].empty()&&!bruh[pnum].empty()&&bruh[pnum].top()==del[pnum].top()){
				bruh[pnum].pop();
				del[pnum].pop();
			}
			if(!bruh[pnum].empty()) val=bruh[pnum].top();
			else val=0;
			return;
		}
		if(S<=m){
			if(!l) l=new node(s,m);
			l->update(S,V,R);
		}
		else{
			if(!r) r=new node(m+1,e);
			r->update(S,V,R);
		}
		val=max((l?l->val:0),(r?r->val:0));
	}
	int query(int S){
		if(s==e){
			if(s==0) return max(S,val-S);
			else return S-s;
		}
		if(S<=m) return (l?l->query(S):0);
		else{
			if(!l||l->val-S<=S-m) return max((l?max(l->val-S,0ll):0),(r?r->query(S):0ll));
			else return l->query(S);
		}
	}
} *root;
int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,q,k;
    cin >> n >> k >> q;
    vector<pair<pair<int,int>,pair<int,int> > > up; //time,loc,type,+-1
    for(int i=0; i<n; i++){
		int a,b,c,d;
		cin >> a >> b >> c >> d;
		up.push_back({{c,a},{b,1}});
		up.push_back({{d+1,a},{b,-1}});
	}
	sort(up.begin(),up.end());
	root=new node(0,1e8+5);
	pair<pair<int,int>,int> qu[q]; //time,loc,index
	for(int i=0; i<q; i++){
		int a,b;
		cin >> a >> b;
		qu[i]={{b,a},i};
	}
	sort(qu,qu+q);
	multiset<int> occ[k+1];
	multiset<int>::iterator it;
	for(int i=1; i<=k; i++){
		occ[i].insert(0);
		occ[i].insert(1e16);
		root->update(0,1e16,-1);
	}
	int ans[q],cnt=0;
	for(int i=0; i<q; i++){
		while(cnt<(int)up.size()&&up[cnt].first.first<=qu[i].first.first){
			if(up[cnt].second.second==1){
				int t=up[cnt].second.first,p=up[cnt].first.second;
				it=occ[t].upper_bound(p);
				int nxt=*it;
				it--;
				int prv=*it;
				root->update(prv,p,nxt);
				root->update(p,nxt,-1);
				occ[t].insert(p);
			}
			else{
				int t=up[cnt].second.first,p=up[cnt].first.second;
				occ[t].erase(occ[t].find(p));
				it=occ[t].upper_bound(p);
				int nxt=*it;
				it--;
				int prv=*it;
				root->update(prv,nxt,p);
				root->update(p,-1,nxt);
			}
			cnt++;
		}
		int loc=qu[i].first.second;
		if(bruh[0].top()==1e16){
			ans[qu[i].second]=-1;
			continue;
		}/*
		int lo=0,hi=1e8,mid;
		while(lo<hi){
			mid=(lo+hi)/2;
			int big=root->query(max(loc-mid-1,0ll));
			if(big<=loc+mid) assert(big>=loc-mid),hi=mid;
			else lo=mid+1;
		}*/
		ans[qu[i].second]=root->query(loc);
	}
	for(int i=0; i<q; i++) cout << ans[i] << '\n';
}
/*4 2 4
3 1 1 10
9 2 2 4
7 2 5 7
4 1 8 10
5 3
5 6
5 9
1 10*/
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |