This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e18+1;
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n,q,d,A,B;
cin >> n >> q >> d >> A >> B;
vector<pair<int,int>> ranges;
for(int i=1;i<=n;i++){
int l,r;cin>>l>>r;
ranges.emplace_back(l,r);
}
ranges.emplace_back(1e12+1,1e12+1);
set<pair<int,int>> accessible;
accessible.insert({0,ranges[0].first-1});
int last = d;
int last2 = ranges[0].first-1+d;
for(int i=0;i<n;i++){
last = max(last,ranges[i].second+1);
if(last2<=ranges[i].second)break;
if(last>=ranges[i+1].first)continue;
accessible.insert({last,ranges[i+1].first-1});
last+=d;
last2 = ranges[i+1].first-1+d;
}
for(int i=1;i<=q;i++){
int x;cin>>x;
auto iter = accessible.upper_bound({x,INF});
if(iter==accessible.begin()) cout << "-1\n";
else {
iter--;
if(x<=iter->second)cout<<x<<'\n';
else cout<<"-1\n";
}
}
}
# | 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... |