Submission #1345192

#TimeUsernameProblemLanguageResultExecution timeMemory
1345192WH8Tower (JOI24_tower)C++17
0 / 100
118 ms1336 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
#define g0(x) get<0>(x)
#define g1(x) get<1>(x)
#define g2(x) get<2>(x)
#define mt make_tuple
#define mp make_pair
#define pb push_back
#define int long long 
#define f first
#define s second
#define pll pair<long long, long long>
#define iii tuple<int,int,int>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()

signed main(){
	int n,qn;cin>>n>>qn;
	int d,a,b;cin>>d>>a>>b;
	vector<pll> fb={{-1,-1}};
	map<int,int> mn;
	for(int i=0;i<n;i++){
		int l,r;cin>>l>>r;
		fb.pb({l, r});
	}
	set<pll> alive;
	for(int i=1;i<n;i++)alive.insert({fb[i+1].s-1, i});
	alive.insert({(int)1e15, n});
	queue<pll> q;
	vector<int> m;
	q.push({0, 0});
	while(!q.empty()){
		auto [ind, l]=q.front(); q.pop();
		m.pb(l);
		//printf("ind %lld, l %lld\n", ind, l);
		if(ind == n) continue;
		int r= fb[ind+1].f-1;
		auto it=alive.lower_bound(mp(l+d, -1ll));
		while(it != alive.end() and fb[it->s].s+1 <= r+d){
			int nind=it->s;
			int nl=max(l+d, fb[it->s].s+1);
			q.push(mp(nind, nl));
			it=alive.erase(it);
		}
	}
	sort(all(m));
	while(qn--){
		int x;cin>>x;
		auto st=*prev(upper_bound(all(m), x));
		auto it=lower_bound(all(fb), mp(st, -1ll));
		if(it != fb.end() and it->f <= x){
			cout<<-1<<'\n';
		}
		else cout<<x<<'\n';
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...