# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
1033822 |
2024-07-25T06:45:23 Z |
정민찬(#10972) |
Fire (BOI24_fire) |
C++17 |
|
208 ms |
59984 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.clear();
for (int i=0; i<t.size(); i++) {
if (t[i].second > mx - m)
a.push_back(t[i]);
}
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);
for (int i=0; i<n; i++) {
seg.update(1, 1, M, a[i].first, i);
}
vector<vector<int>> r(n, vector<int>(20)), cnt(n, vector<int>(20));
for (int i=0; i<n; i++) {
if (d[a[i].second-1] >= m) {
int idx = upper_bound(d.begin(), d.end(), d[a[i].second-1] - m) - d.begin();
r[i][0] = seg.query(1, 1, M, 1, idx);
if (r[i][0] == -1) {
r[i][0] = seg.query(1, 1, M, a[i].first, M);
}
}
else
r[i][0] = seg.query(1, 1, M, a[i].first, a[i].second);
if (r[i][0] == -1) r[i][0] = i;
cnt[i][0] = (r[i][0] - i + n) % n;
}
for (int lv=1; lv<20; lv++) {
for (int i=0; i<n; i++) {
r[i][lv] = r[r[i][lv-1]][lv-1];
cnt[i][lv] = cnt[i][lv-1] + cnt[r[i][lv-1]][lv-1];
}
}
int ans = 1e9;
for (int i=0; i<n; i++) {
if (cnt[i][0] == 0) continue;
int cur = 0;
int x = i, y = 0;
for (int lv=19; lv>=0; lv--) {
if (y + cnt[x][lv] < n) {
cur += (1 << lv);
y += cnt[x][lv];
x = r[x][lv];
}
}
if (y + cnt[x][0] >= n)
ans = min(ans, cur + 1);
}
if (ans > n) 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;
| ~~^~~
Main.cpp: In function 'int main()':
Main.cpp:57:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for (int i=0; i<t.size(); i++) {
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
452 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
456 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
452 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
456 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
460 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
456 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
452 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
456 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
460 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
456 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
2 ms |
604 KB |
Output is correct |
40 |
Correct |
4 ms |
1628 KB |
Output is correct |
41 |
Correct |
4 ms |
1884 KB |
Output is correct |
42 |
Correct |
4 ms |
1624 KB |
Output is correct |
43 |
Correct |
2 ms |
344 KB |
Output is correct |
44 |
Correct |
4 ms |
1884 KB |
Output is correct |
45 |
Correct |
5 ms |
1884 KB |
Output is correct |
46 |
Correct |
4 ms |
1884 KB |
Output is correct |
47 |
Correct |
1 ms |
600 KB |
Output is correct |
48 |
Correct |
1 ms |
592 KB |
Output is correct |
49 |
Correct |
2 ms |
1116 KB |
Output is correct |
50 |
Correct |
5 ms |
1628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
460 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
4 ms |
1884 KB |
Output is correct |
16 |
Correct |
4 ms |
1628 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
4 ms |
1880 KB |
Output is correct |
19 |
Correct |
3 ms |
600 KB |
Output is correct |
20 |
Correct |
20 ms |
2660 KB |
Output is correct |
21 |
Correct |
58 ms |
12508 KB |
Output is correct |
22 |
Correct |
54 ms |
10832 KB |
Output is correct |
23 |
Correct |
205 ms |
56900 KB |
Output is correct |
24 |
Correct |
151 ms |
48720 KB |
Output is correct |
25 |
Correct |
45 ms |
5064 KB |
Output is correct |
26 |
Correct |
99 ms |
32844 KB |
Output is correct |
27 |
Correct |
167 ms |
57932 KB |
Output is correct |
28 |
Correct |
52 ms |
9552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
452 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
1884 KB |
Output is correct |
13 |
Correct |
5 ms |
1880 KB |
Output is correct |
14 |
Correct |
5 ms |
1628 KB |
Output is correct |
15 |
Correct |
20 ms |
2788 KB |
Output is correct |
16 |
Correct |
178 ms |
56904 KB |
Output is correct |
17 |
Correct |
208 ms |
59980 KB |
Output is correct |
18 |
Incorrect |
206 ms |
59984 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
452 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
456 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
460 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
456 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
2 ms |
604 KB |
Output is correct |
40 |
Correct |
4 ms |
1628 KB |
Output is correct |
41 |
Correct |
4 ms |
1884 KB |
Output is correct |
42 |
Correct |
4 ms |
1624 KB |
Output is correct |
43 |
Correct |
2 ms |
344 KB |
Output is correct |
44 |
Correct |
4 ms |
1884 KB |
Output is correct |
45 |
Correct |
5 ms |
1884 KB |
Output is correct |
46 |
Correct |
4 ms |
1884 KB |
Output is correct |
47 |
Correct |
1 ms |
600 KB |
Output is correct |
48 |
Correct |
1 ms |
592 KB |
Output is correct |
49 |
Correct |
2 ms |
1116 KB |
Output is correct |
50 |
Correct |
5 ms |
1628 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
0 ms |
348 KB |
Output is correct |
56 |
Correct |
0 ms |
348 KB |
Output is correct |
57 |
Correct |
1 ms |
348 KB |
Output is correct |
58 |
Correct |
1 ms |
348 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
1 ms |
348 KB |
Output is correct |
61 |
Correct |
0 ms |
460 KB |
Output is correct |
62 |
Correct |
0 ms |
348 KB |
Output is correct |
63 |
Correct |
1 ms |
348 KB |
Output is correct |
64 |
Correct |
0 ms |
348 KB |
Output is correct |
65 |
Correct |
4 ms |
1884 KB |
Output is correct |
66 |
Correct |
4 ms |
1628 KB |
Output is correct |
67 |
Correct |
1 ms |
348 KB |
Output is correct |
68 |
Correct |
4 ms |
1880 KB |
Output is correct |
69 |
Correct |
3 ms |
600 KB |
Output is correct |
70 |
Correct |
20 ms |
2660 KB |
Output is correct |
71 |
Correct |
58 ms |
12508 KB |
Output is correct |
72 |
Correct |
54 ms |
10832 KB |
Output is correct |
73 |
Correct |
205 ms |
56900 KB |
Output is correct |
74 |
Correct |
151 ms |
48720 KB |
Output is correct |
75 |
Correct |
45 ms |
5064 KB |
Output is correct |
76 |
Correct |
99 ms |
32844 KB |
Output is correct |
77 |
Correct |
167 ms |
57932 KB |
Output is correct |
78 |
Correct |
52 ms |
9552 KB |
Output is correct |
79 |
Correct |
1 ms |
348 KB |
Output is correct |
80 |
Correct |
0 ms |
348 KB |
Output is correct |
81 |
Correct |
1 ms |
348 KB |
Output is correct |
82 |
Correct |
1 ms |
348 KB |
Output is correct |
83 |
Correct |
0 ms |
348 KB |
Output is correct |
84 |
Correct |
1 ms |
348 KB |
Output is correct |
85 |
Correct |
0 ms |
348 KB |
Output is correct |
86 |
Correct |
1 ms |
348 KB |
Output is correct |
87 |
Correct |
1 ms |
452 KB |
Output is correct |
88 |
Correct |
0 ms |
348 KB |
Output is correct |
89 |
Correct |
1 ms |
348 KB |
Output is correct |
90 |
Correct |
5 ms |
1884 KB |
Output is correct |
91 |
Correct |
5 ms |
1880 KB |
Output is correct |
92 |
Correct |
5 ms |
1628 KB |
Output is correct |
93 |
Correct |
20 ms |
2788 KB |
Output is correct |
94 |
Correct |
178 ms |
56904 KB |
Output is correct |
95 |
Correct |
208 ms |
59980 KB |
Output is correct |
96 |
Incorrect |
206 ms |
59984 KB |
Output isn't correct |
97 |
Halted |
0 ms |
0 KB |
- |