이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
set<pair<int,int>> tempaccessible;
auto get_latest = [&](int x){
auto iter = tempaccessible.upper_bound({x,INF});
if(iter==tempaccessible.begin()) return iter->first;
else {
iter--;
if(x<=iter->second)return x;
else {
iter++;
if(iter==tempaccessible.end())return INF;
else return iter->first;
}
}
};
accessible.insert({0,ranges[0].first-1});
tempaccessible.insert({d,ranges[0].first-1+d});
for(int i=0;i<n;i++){
int last = get_latest(ranges[i].second+1);
if(last>=ranges[i+1].first)continue;
accessible.insert({last,ranges[i+1].first-1});
tempaccessible.insert({last+d,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... |