Submission #1102061

#TimeUsernameProblemLanguageResultExecution timeMemory
1102061PacybwoahTower (JOI24_tower)C++17
25 / 100
157 ms35304 KiB
#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 + 1, 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...