# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1033775 |
2024-07-25T05:50:20 Z |
정민찬(#10972) |
Fire (BOI24_fire) |
C++17 |
|
192 ms |
18508 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
struct SegmentTree{
vector<int> tree;
void init(int n) {
int sz = 1 << __lg(n-1) + 2;
tree.assign(sz, -1);
}
void update(int node, int s, int e, int tar, int val) {
if (s > tar || tar > e) return;
if (s == e) {
tree[node] = val;
return;
}
int mid = s + e >> 1;
update(node*2, s, mid, tar, val);
update(node*2+1, mid+1, e, tar, val);
tree[node] = max(tree[node*2], tree[node*2+1]);
}
int query(int node, int s, int e, int l, int r) {
if (l > e || s > r) return -1;
if (l <= s && e <= r) return tree[node];
int mid = s + e >> 1;
return max(query(node*2, s, mid, l, r), query(node*2+1, mid+1, e, l, r));
}
};
SegmentTree seg;
int main() {
ios_base :: sync_with_stdio(false); cin.tie(NULL);
int n, m;
cin >> n >> m;
vector<pair<int,int>> a(n);
for (int i=0; i<n; i++) {
cin >> a[i].first >> a[i].second;
if (a[i].first > a[i].second) a[i].second += m;
}
sort(a.begin(), a.end(), [&] (pair<int,int> &u, pair<int,int> &v) {
if (u.first == v.first) return u.second > v.second;
return u.first < v.first;
});
vector<pair<int,int>> t = {a[0]};
int mx = a[0].second;
for (int i=1; i<n; i++) {
if (a[i].second > mx) {
t.push_back(a[i]);
mx = a[i].second;
}
}
a = t;
n = a.size();
vector<int> d;
for (int i=0; i<n; i++) {
d.push_back(a[i].first);
d.push_back(a[i].second);
}
sort(d.begin(), d.end());
d.erase(unique(d.begin(), d.end()), d.end());
for (int i=0; i<n; i++) {
a[i].first = lower_bound(d.begin(), d.end(), a[i].first) - d.begin() + 1;
a[i].second = lower_bound(d.begin(), d.end(), a[i].second) - d.begin() + 1;
}
int M = d.size();
seg.init(M);
set<int> s;
for (int i=0; i<n; i++) {
s.insert(i);
seg.update(1, 1, M, a[i].first, i);
}
int ans = 1e9;
while (!s.empty()) {
int x = *s.begin();
s.erase(s.begin());
seg.update(1, 1, M, a[x].first, -1);
bool flag = true;
int cnt = 1;
int st = a[x].first;
while (true) {
int nxt = seg.query(1, 1, M, 1, a[x].second);
if (nxt == -1 || a[nxt].second <= a[x].second) {
flag = false;
break;
}
s.erase(nxt);
seg.update(1, 1, M, a[nxt].first, -1);
x = nxt;
cnt ++;
if (d[a[nxt].second-1] - d[st-1] >= m) break;
}
if (!flag) break;
ans = min(ans, cnt);
}
if (ans == 1e9) cout << "-1\n";
else cout << ans << '\n';
}
Compilation message
Main.cpp: In member function 'void SegmentTree::init(int)':
Main.cpp:11:33: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
11 | int sz = 1 << __lg(n-1) + 2;
| ~~~~~~~~~~^~~
Main.cpp: In member function 'void SegmentTree::update(int, int, int, int, int)':
Main.cpp:20:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
20 | int mid = s + e >> 1;
| ~~^~~
Main.cpp: In member function 'int SegmentTree::query(int, int, int, int, int)':
Main.cpp:28:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
28 | int mid = s + e >> 1;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
376 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
3 ms |
860 KB |
Output is correct |
16 |
Correct |
3 ms |
860 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
3 ms |
860 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
19 ms |
1884 KB |
Output is correct |
21 |
Correct |
49 ms |
3932 KB |
Output is correct |
22 |
Correct |
46 ms |
3664 KB |
Output is correct |
23 |
Correct |
139 ms |
16456 KB |
Output is correct |
24 |
Correct |
112 ms |
15688 KB |
Output is correct |
25 |
Correct |
44 ms |
1884 KB |
Output is correct |
26 |
Correct |
87 ms |
10068 KB |
Output is correct |
27 |
Correct |
137 ms |
16352 KB |
Output is correct |
28 |
Correct |
45 ms |
3156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
360 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
860 KB |
Output is correct |
13 |
Correct |
3 ms |
860 KB |
Output is correct |
14 |
Correct |
3 ms |
860 KB |
Output is correct |
15 |
Correct |
19 ms |
1884 KB |
Output is correct |
16 |
Correct |
141 ms |
16484 KB |
Output is correct |
17 |
Incorrect |
192 ms |
18508 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |