이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<cassert>
#include<set>
using namespace std;
typedef long long ll;
ll inf = 8e18;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
ll d, a, b;
cin >> d >> a >> b;
vector<pair<ll, ll>> vec, free;
for(int i = 0; i < n; i++){
ll l, r;
cin >> l >> r;
vec.emplace_back(l, r);
if(i == 0) free.emplace_back(0, l - 1);
else free.emplace_back(vec[i - 1].second + 1, l - 1);
}
free.emplace_back(vec[n - 1].second, inf);
vector<pair<ll, int>> queries;
vector<ll> ans(q, -1);
for(int i = 0; i < q; i++){
ll x;
cin >> x;
queries.emplace_back(x, i);
}
sort(queries.begin(), queries.end());
int ptr = -1;
set<pair<ll, ll>> s;
for(auto &[l, r]: free){
ll fst = r + 1;
if(l == 0) fst = 0;
else{
auto iter = s.lower_bound(make_pair(l, -1));
if(iter != s.end()){
if((*iter).first <= r) fst = (*iter).first;
}
if(iter != s.begin()){
iter = prev(iter);
if((*iter).second >= l) fst = l;
}
}
while(ptr < q - 1 && queries[ptr + 1].first < l) ptr++;
while(ptr < q - 1 && queries[ptr + 1].first <= r){
ptr++;
if(fst <= queries[ptr].first) ans[queries[ptr].second] = queries[ptr].first;
}
if(fst <= r) s.emplace(fst + d, r + d);
}
for(int i = 0; i < q; i++) cout << ans[i] << "\n";
}
// g++ -std=c++17 -Wall -Wextra -Wshadow -fsanitize=undefined -fsanitize=address -o run tower.cpp
# | 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... |