Submission #1080415

#TimeUsernameProblemLanguageResultExecution timeMemory
1080415someoneFire (BOI24_fire)C++14
100 / 100
294 ms48108 KiB
#include <bits/stdc++.h> #define sz(x) ((int)x.size()) #define all(x) x.begin(), x.end() using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; using namespace std; const int N = 4e5 + 42, T = 18, INF = 1e9 + 42; struct Inter { int l, r; }; struct Event { int t, id, isDeb; }; int bl[T][N]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<Inter> inter; for(int i = 0; i < n; i++) { int s, e; cin >> s >> e; if(s < e) { inter.push_back({s, e}); inter.push_back({s+m, e+m}); } else { inter.push_back({s, e+m}); } } vector<Event> ev; for(int i = 0; i < sz(inter); i++) { ev.push_back({inter[i].l, i, 0}); ev.push_back({inter[i].r, i, 1}); } sort(all(ev), [](Event a, Event b) { if(a.t == b.t) return a.isDeb < b.isDeb; return a.t < b.t; }); set<array<int, 2>> fins; vector<bool> occ(sz(inter)); for(Event e : ev) { if(occ[e.id]) { occ[e.id] = 0; auto it = fins.end(); it--; bl[0][e.id] = (*it)[1]; fins.erase(array<int, 2>{inter[e.id].r, e.id}); } else { occ[e.id] = 1; fins.insert(array<int, 2>{inter[e.id].r, e.id}); } } for(int i = 1; i < T; i++) for(int j = 0; j < sz(inter); j++) bl[i][j] = bl[i-1][bl[i-1][j]]; int mini = INF; for(int i = 0; i < sz(inter); i++) if(inter[i].l <= m) { int id = i, ans = 2; for(int j = T-1; j >= 0; j--) if((j == 0 || bl[j][id] != bl[j-1][id]) && inter[bl[j][id]].r < inter[i].l + m) { ans += (1 << j); id = bl[j][id]; } if(inter[bl[0][id]].r >= inter[i].l + m) mini = min(mini, ans); } cout << (mini == INF ? -1 : mini) << '\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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...