Submission #1356826

#TimeUsernameProblemLanguageResultExecution timeMemory
1356826khangai11New Home (APIO18_new_home)C++20
5 / 100
5096 ms78064 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void solve(){
	ll n,k,q;
	cin>>n>>k>>q;
	vector<ll> x(n),t(n),l(n),r(n);
	map<ll,vector<pair<ll,pair<ll,ll>>>> mp;
	for(ll a=0;a<n;a++){
		cin>>x[a]>>t[a]>>l[a]>>r[a];
		mp[l[a]].push_back({1,{x[a],t[a]}});
		mp[r[a]+1].push_back({2,{x[a],t[a]}});
	}
	vector<ll> z(q),y(q);
	vector<pair<pair<ll,ll>,ll>> Q(q);
	for(ll a=0;a<q;a++){
		cin>>z[a]>>y[a];
		Q[a]={{y[a],z[a]},a};
	}
	sort(Q.begin(),Q.end());
	ll year=0;
	vector<multiset<ll>> st(k+1);
	vector<ll> ans(q);
	auto i=mp.begin();
	for(ll a=0;a<q;a++){
		ll year1=Q[a].first.first;
		if(i!=mp.end())
		while((*i).first<=year1 and i!=mp.end()){
			if(i==mp.end()){
				break;
			}
			for(auto z:(*i).second){
				if(z.first==1){
					st[z.second.second].insert(z.second.first);
				}else{
					st[z.second.second].erase(lower_bound(st[z.second.second].begin(),st[z.second.second].end(),z.second.first));
				}
			}
			year=(*i).first;
			i++;
		}
		ll D=0;
		for(ll b=1;b<=k;b++){
			ll d=1e9;
			auto j=lower_bound(st[b].begin(),st[b].end(),Q[a].first.second);
			if(j!=st[b].end()){
				d=min(d,abs(Q[a].first.second-*j));
			}
			if(j!=st[b].begin()){
				j--;
				d=min(d,abs(Q[a].first.second-*j));
			}
			if(d==1e9){
				D=-1;
				break;
			}else{
				D=max(D,d);
			}
		}
		ans[Q[a].second]=D;
	}
	for(ll a=0;a<q;a++){
		cout<<ans[a]<<endl;
	}
}
signed main(){
	ios::sync_with_stdio();
	cin.tie(0);
	cout.tie(0);
	ll t=1;
//	cin>>t;
	for(ll a=0;a<t;a++){
		solve();
	}
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...