제출 #1111496

#제출 시각아이디문제언어결과실행 시간메모리
1111496gelastropodFire (BOI24_fire)C++14
0 / 100
1 ms504 KiB
#include<bits/stdc++.h> using namespace std; int M; vector<pair<int, int>> tree; void upd(int n, int x, int i) { while (n <= M) { if (tree[n].first < x) tree[n] = {x, i}; n += n & (-n); } } pair<int, int> qry(int a) { pair<int, int> ans = {-1, -1}; while (a > 0) { if (ans.first < tree[a].first) ans = tree[a]; a -= a & (-a); } return ans; } signed main() { int N, a, b; cin >> N >> M; tree = vector<pair<int, int>>(M + 1, {-1, -1}); set<pair<int, int>> pairss; vector<pair<int, int>> pairs; vector<bool> works(N, true); for (int i = 0; i < N; i++) { cin >> a >> b; if (a > b) b += M; pairss.insert({a, b}); } int counter = 0; while (!pairss.empty()) { pairs.push_back(*pairss.begin()); upd(pairss.begin()->first, pairss.begin()->second, counter); counter++; pairss.erase(pairss.begin()); } int anss = INT_MAX; for (int i = 0; i < N; i++) { works[i] = false; int num = 1; int ca = pairs[i].first, cb = pairs[i].second; int prev = i; while (cb - ca < M) { auto z = qry(cb); if (z.first != -1 && z.second != prev && z.second != -1) { cb = max(cb, z.first); works[z.second] = false; num++; } else break; prev = z.second; } if (cb - ca >= M) anss = min(num, anss); } if (anss == LLONG_MAX) cout << "-1\n"; else cout << anss << '\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...