# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1080397 |
2024-08-29T09:34:37 Z |
someone |
Fire (BOI24_fire) |
C++14 |
|
1 ms |
8540 KB |
#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++) {
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 time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
8536 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Incorrect |
1 ms |
6616 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
8536 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Incorrect |
1 ms |
6616 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
8536 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Incorrect |
1 ms |
6616 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Incorrect |
1 ms |
8540 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6744 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6748 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
8536 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Incorrect |
1 ms |
6616 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |