# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1056150 |
2024-08-13T07:58:48 Z |
anango |
Fire (BOI24_fire) |
C++17 |
|
1066 ms |
270252 KB |
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int K = 20;
int INF = 1LL<<60;
signed main() {
#ifndef ONLINE_JUDGE
// for getting input from input.txt
//freopen("input.txt", "r", stdin);
// for writing output to output.txt
//freopen("output.txt", "w", stdout);
#endif
#ifdef ONLINE_JUDGE
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#endif //fast IO
int n,m; cin >> n >> m;
vector<pair<int,int>> segments;
vector<int> coords;
//coords.push_back(0); //0 to m-1
map<int,int> rev;
for (int i=0; i<n; i++) {
int l,r; cin >> l >> r;
if (l<r) {
segments.push_back({l,r});
coords.push_back(l);
coords.push_back(r);
segments.push_back({m+l,m+r});
coords.push_back(m+l);
coords.push_back(m+r);
}
else {
segments.push_back({l,m+r});
coords.push_back(l);
coords.push_back(m+r);
}
}
int n0 = segments.size();
sort(coords.begin(), coords.end());
coords.erase(unique(coords.begin(), coords.end()),coords.end());
int k = coords.size();
for (int i=0; i<k; i++) {
rev[coords[i]] = i;
}
for (int i=0; i<n0; i++) {
segments[i] = {rev[segments[i].first],rev[segments[i].second]};
}
vector<int> go(k,-1);
multiset<int> ends;
set<int> indices;
sort(segments.begin(), segments.end());
int pointer = 0;
int lpointer = 0;
for (int i=0; i<k; i++) {
while (pointer<n0 && segments[pointer].first==i) {
indices.insert(pointer);
ends.insert(segments[pointer].second);
pointer++;
}
if (!ends.size()) {
go[i] = -1;
}
else {
go[i] = *ends.rbegin();
}
while (lpointer<n0 && segments[lpointer].second==i) {
indices.erase(lpointer);
ends.erase(ends.find(segments[lpointer].second));
lpointer++;
}
}
for (int i=0; i<k; i++) {
//cout << i <<" " << coords[i] <<" " << go[i] << " " << coords[go[i]] << endl;
}
vector<vector<int>> lift(k,vector<int>(K,-1));
for (int i=0; i<k; i++) {
lift[i][0] = go[i];
}
for (int p=1; p<K; p++) {
for (int i=0; i<k; i++) {
lift[i][p] = lift[lift[i][p-1]][p-1];
}
}
int mians = INF;
for (int i=0; i<k; i++) {
int cur = i;
int ct = 0;
for (int p=K-1; p>=0; p--) {
if (coords[lift[cur][p]]<coords[i]+m) {
cur = lift[cur][p];
ct+=1<<p;
}
}
int p = 0;
if (coords[lift[cur][p]]<=coords[i]+m) {
cur = lift[cur][p];
ct++;
}
if (coords[cur]>=coords[i]+m) {
mians=min(mians,ct);
}
}
if (mians<INF) cout << mians << endl;
else cout << -1 << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
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 |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 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 |
348 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 |
0 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 |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
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 |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 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 |
348 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 |
0 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 |
0 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 |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
0 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
604 KB |
Output is correct |
32 |
Correct |
1 ms |
604 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
1 ms |
604 KB |
Output is correct |
35 |
Correct |
1 ms |
604 KB |
Output is correct |
36 |
Correct |
1 ms |
604 KB |
Output is correct |
37 |
Correct |
1 ms |
604 KB |
Output is correct |
38 |
Correct |
0 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
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 |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 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 |
348 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 |
0 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 |
0 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 |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
0 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
604 KB |
Output is correct |
32 |
Correct |
1 ms |
604 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
1 ms |
604 KB |
Output is correct |
35 |
Correct |
1 ms |
604 KB |
Output is correct |
36 |
Correct |
1 ms |
604 KB |
Output is correct |
37 |
Correct |
1 ms |
604 KB |
Output is correct |
38 |
Correct |
0 ms |
604 KB |
Output is correct |
39 |
Correct |
14 ms |
6872 KB |
Output is correct |
40 |
Correct |
13 ms |
7124 KB |
Output is correct |
41 |
Correct |
14 ms |
6032 KB |
Output is correct |
42 |
Correct |
10 ms |
3288 KB |
Output is correct |
43 |
Correct |
8 ms |
3796 KB |
Output is correct |
44 |
Correct |
10 ms |
4316 KB |
Output is correct |
45 |
Correct |
10 ms |
4156 KB |
Output is correct |
46 |
Correct |
10 ms |
4284 KB |
Output is correct |
47 |
Correct |
13 ms |
6876 KB |
Output is correct |
48 |
Correct |
14 ms |
6872 KB |
Output is correct |
49 |
Correct |
11 ms |
6936 KB |
Output is correct |
50 |
Correct |
8 ms |
3288 KB |
Output is correct |
# |
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 |
436 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
608 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
16 ms |
6072 KB |
Output is correct |
16 |
Correct |
9 ms |
3288 KB |
Output is correct |
17 |
Correct |
8 ms |
3544 KB |
Output is correct |
18 |
Correct |
9 ms |
4312 KB |
Output is correct |
19 |
Correct |
13 ms |
6868 KB |
Output is correct |
20 |
Correct |
157 ms |
29648 KB |
Output is correct |
21 |
Correct |
1008 ms |
267608 KB |
Output is correct |
22 |
Correct |
1014 ms |
267144 KB |
Output is correct |
23 |
Correct |
511 ms |
125840 KB |
Output is correct |
24 |
Correct |
980 ms |
270252 KB |
Output is correct |
25 |
Correct |
614 ms |
131716 KB |
Output is correct |
26 |
Correct |
648 ms |
163984 KB |
Output is correct |
27 |
Correct |
657 ms |
154236 KB |
Output is correct |
28 |
Correct |
881 ms |
262020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
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 |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
604 KB |
Output is correct |
12 |
Correct |
12 ms |
6104 KB |
Output is correct |
13 |
Correct |
8 ms |
3288 KB |
Output is correct |
14 |
Correct |
8 ms |
3284 KB |
Output is correct |
15 |
Correct |
157 ms |
32512 KB |
Output is correct |
16 |
Correct |
519 ms |
123224 KB |
Output is correct |
17 |
Correct |
956 ms |
231832 KB |
Output is correct |
18 |
Correct |
986 ms |
221556 KB |
Output is correct |
19 |
Correct |
868 ms |
230280 KB |
Output is correct |
20 |
Correct |
555 ms |
123800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
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 |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 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 |
348 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 |
0 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 |
0 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 |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
0 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
604 KB |
Output is correct |
32 |
Correct |
1 ms |
604 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
1 ms |
604 KB |
Output is correct |
35 |
Correct |
1 ms |
604 KB |
Output is correct |
36 |
Correct |
1 ms |
604 KB |
Output is correct |
37 |
Correct |
1 ms |
604 KB |
Output is correct |
38 |
Correct |
0 ms |
604 KB |
Output is correct |
39 |
Correct |
14 ms |
6872 KB |
Output is correct |
40 |
Correct |
13 ms |
7124 KB |
Output is correct |
41 |
Correct |
14 ms |
6032 KB |
Output is correct |
42 |
Correct |
10 ms |
3288 KB |
Output is correct |
43 |
Correct |
8 ms |
3796 KB |
Output is correct |
44 |
Correct |
10 ms |
4316 KB |
Output is correct |
45 |
Correct |
10 ms |
4156 KB |
Output is correct |
46 |
Correct |
10 ms |
4284 KB |
Output is correct |
47 |
Correct |
13 ms |
6876 KB |
Output is correct |
48 |
Correct |
14 ms |
6872 KB |
Output is correct |
49 |
Correct |
11 ms |
6936 KB |
Output is correct |
50 |
Correct |
8 ms |
3288 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 |
436 KB |
Output is correct |
56 |
Correct |
0 ms |
348 KB |
Output is correct |
57 |
Correct |
0 ms |
348 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
0 ms |
604 KB |
Output is correct |
60 |
Correct |
1 ms |
608 KB |
Output is correct |
61 |
Correct |
1 ms |
604 KB |
Output is correct |
62 |
Correct |
1 ms |
604 KB |
Output is correct |
63 |
Correct |
1 ms |
604 KB |
Output is correct |
64 |
Correct |
1 ms |
604 KB |
Output is correct |
65 |
Correct |
16 ms |
6072 KB |
Output is correct |
66 |
Correct |
9 ms |
3288 KB |
Output is correct |
67 |
Correct |
8 ms |
3544 KB |
Output is correct |
68 |
Correct |
9 ms |
4312 KB |
Output is correct |
69 |
Correct |
13 ms |
6868 KB |
Output is correct |
70 |
Correct |
157 ms |
29648 KB |
Output is correct |
71 |
Correct |
1008 ms |
267608 KB |
Output is correct |
72 |
Correct |
1014 ms |
267144 KB |
Output is correct |
73 |
Correct |
511 ms |
125840 KB |
Output is correct |
74 |
Correct |
980 ms |
270252 KB |
Output is correct |
75 |
Correct |
614 ms |
131716 KB |
Output is correct |
76 |
Correct |
648 ms |
163984 KB |
Output is correct |
77 |
Correct |
657 ms |
154236 KB |
Output is correct |
78 |
Correct |
881 ms |
262020 KB |
Output is correct |
79 |
Correct |
0 ms |
344 KB |
Output is correct |
80 |
Correct |
0 ms |
348 KB |
Output is correct |
81 |
Correct |
0 ms |
348 KB |
Output is correct |
82 |
Correct |
0 ms |
348 KB |
Output is correct |
83 |
Correct |
0 ms |
348 KB |
Output is correct |
84 |
Correct |
0 ms |
348 KB |
Output is correct |
85 |
Correct |
0 ms |
348 KB |
Output is correct |
86 |
Correct |
1 ms |
604 KB |
Output is correct |
87 |
Correct |
0 ms |
604 KB |
Output is correct |
88 |
Correct |
1 ms |
604 KB |
Output is correct |
89 |
Correct |
0 ms |
604 KB |
Output is correct |
90 |
Correct |
12 ms |
6104 KB |
Output is correct |
91 |
Correct |
8 ms |
3288 KB |
Output is correct |
92 |
Correct |
8 ms |
3284 KB |
Output is correct |
93 |
Correct |
157 ms |
32512 KB |
Output is correct |
94 |
Correct |
519 ms |
123224 KB |
Output is correct |
95 |
Correct |
956 ms |
231832 KB |
Output is correct |
96 |
Correct |
986 ms |
221556 KB |
Output is correct |
97 |
Correct |
868 ms |
230280 KB |
Output is correct |
98 |
Correct |
555 ms |
123800 KB |
Output is correct |
99 |
Correct |
998 ms |
267604 KB |
Output is correct |
100 |
Correct |
1066 ms |
267148 KB |
Output is correct |
101 |
Correct |
1038 ms |
268200 KB |
Output is correct |
102 |
Correct |
1043 ms |
268428 KB |
Output is correct |
103 |
Correct |
713 ms |
161160 KB |
Output is correct |
104 |
Correct |
908 ms |
257188 KB |
Output is correct |
105 |
Correct |
664 ms |
266628 KB |
Output is correct |