제출 #1021873

#제출 시각아이디문제언어결과실행 시간메모리
1021873PurpleCrayonTower (JOI24_tower)C++17
25 / 100
202 ms27656 KiB
#include <bits/stdc++.h> using namespace std; #define sz(v) int(v.size()) #define ar array typedef long long ll; const int N = 3e5+10, MOD = 1e9+7; const ll INF = 1e18+10; int n, q; ll d, a, b; pair<ll, ll> dead[N]; set<pair<ll, ll>> can; bool is_dead(ll x) { int i = upper_bound(dead, dead + n, make_pair(x, INF)) - dead; return 0 <= i && i < n && dead[i].first <= x && x <= dead[i].second; } bool qry_can(ll x) { auto it = can.upper_bound(make_pair(x, INF)); if (it != can.begin()) { --it; if (it->first <= x && x <= it->second) return true; } return false; } void solve() { cin >> n >> q; cin >> d >> a >> b; for (int i = 0; i < n; i++) { ll l, r; cin >> l >> r; dead[i] = {l, r}; } vector<pair<ll, ll>> alive; ll prv = -1; for (int i = 0; i < n; i++) { alive.emplace_back(prv + 1, dead[i].first - 1); prv = dead[i].second; } alive.emplace_back(prv + 1, INF);; can.insert(alive[0]); for (int i = 1; i < sz(alive); i++) { auto [l, r] = alive[i]; if (qry_can(l - d)) { can.insert(alive[i]); } else { auto it = can.lower_bound(make_pair(l - d, -INF)); if (it != can.end() && it->first + d <= r) { can.insert({it->first + d, r}); } } } while (q--) { ll x; cin >> x; cout << (qry_can(x) ? x : -1) << '\n'; } } int main() { ios::sync_with_stdio(false); cin.tie(0); int T = 1; // cin >> T; while (T--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...