제출 #1038267

#제출 시각아이디문제언어결과실행 시간메모리
1038267UnforgettableplTower (JOI24_tower)C++17
25 / 100
276 ms36444 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...