# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1056153 |
2024-08-13T07:59:16 Z |
anango |
Fire (BOI24_fire) |
C++17 |
|
1059 ms |
266896 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 |
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 |
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 |
1 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 |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 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 |
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 |
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 |
1 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 |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 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 |
604 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
860 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
0 ms |
604 KB |
Output is correct |
32 |
Correct |
0 ms |
604 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
0 ms |
604 KB |
Output is correct |
35 |
Correct |
0 ms |
860 KB |
Output is correct |
36 |
Correct |
1 ms |
604 KB |
Output is correct |
37 |
Correct |
1 ms |
860 KB |
Output is correct |
38 |
Correct |
1 ms |
604 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 |
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 |
1 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 |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 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 |
604 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
860 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
0 ms |
604 KB |
Output is correct |
32 |
Correct |
0 ms |
604 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
0 ms |
604 KB |
Output is correct |
35 |
Correct |
0 ms |
860 KB |
Output is correct |
36 |
Correct |
1 ms |
604 KB |
Output is correct |
37 |
Correct |
1 ms |
860 KB |
Output is correct |
38 |
Correct |
1 ms |
604 KB |
Output is correct |
39 |
Correct |
13 ms |
6872 KB |
Output is correct |
40 |
Correct |
12 ms |
7016 KB |
Output is correct |
41 |
Correct |
11 ms |
6020 KB |
Output is correct |
42 |
Correct |
7 ms |
3288 KB |
Output is correct |
43 |
Correct |
7 ms |
3544 KB |
Output is correct |
44 |
Correct |
8 ms |
4056 KB |
Output is correct |
45 |
Correct |
8 ms |
4312 KB |
Output is correct |
46 |
Correct |
9 ms |
4312 KB |
Output is correct |
47 |
Correct |
11 ms |
6904 KB |
Output is correct |
48 |
Correct |
11 ms |
6772 KB |
Output is correct |
49 |
Correct |
10 ms |
7008 KB |
Output is correct |
50 |
Correct |
9 ms |
3288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
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 |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
860 KB |
Output is correct |
15 |
Correct |
13 ms |
5940 KB |
Output is correct |
16 |
Correct |
8 ms |
3288 KB |
Output is correct |
17 |
Correct |
11 ms |
3544 KB |
Output is correct |
18 |
Correct |
8 ms |
4056 KB |
Output is correct |
19 |
Correct |
11 ms |
7032 KB |
Output is correct |
20 |
Correct |
143 ms |
30864 KB |
Output is correct |
21 |
Correct |
1018 ms |
266892 KB |
Output is correct |
22 |
Correct |
1059 ms |
266892 KB |
Output is correct |
23 |
Correct |
571 ms |
121620 KB |
Output is correct |
24 |
Correct |
969 ms |
266124 KB |
Output is correct |
25 |
Correct |
640 ms |
126996 KB |
Output is correct |
26 |
Correct |
633 ms |
159888 KB |
Output is correct |
27 |
Correct |
612 ms |
149900 KB |
Output is correct |
28 |
Correct |
943 ms |
259172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 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 |
14 ms |
6056 KB |
Output is correct |
13 |
Correct |
7 ms |
3284 KB |
Output is correct |
14 |
Correct |
8 ms |
3288 KB |
Output is correct |
15 |
Correct |
140 ms |
28828 KB |
Output is correct |
16 |
Correct |
515 ms |
122084 KB |
Output is correct |
17 |
Correct |
931 ms |
227472 KB |
Output is correct |
18 |
Correct |
982 ms |
216468 KB |
Output is correct |
19 |
Correct |
850 ms |
226144 KB |
Output is correct |
20 |
Correct |
559 ms |
122816 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 |
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 |
1 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 |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 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 |
604 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
860 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
0 ms |
604 KB |
Output is correct |
32 |
Correct |
0 ms |
604 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
0 ms |
604 KB |
Output is correct |
35 |
Correct |
0 ms |
860 KB |
Output is correct |
36 |
Correct |
1 ms |
604 KB |
Output is correct |
37 |
Correct |
1 ms |
860 KB |
Output is correct |
38 |
Correct |
1 ms |
604 KB |
Output is correct |
39 |
Correct |
13 ms |
6872 KB |
Output is correct |
40 |
Correct |
12 ms |
7016 KB |
Output is correct |
41 |
Correct |
11 ms |
6020 KB |
Output is correct |
42 |
Correct |
7 ms |
3288 KB |
Output is correct |
43 |
Correct |
7 ms |
3544 KB |
Output is correct |
44 |
Correct |
8 ms |
4056 KB |
Output is correct |
45 |
Correct |
8 ms |
4312 KB |
Output is correct |
46 |
Correct |
9 ms |
4312 KB |
Output is correct |
47 |
Correct |
11 ms |
6904 KB |
Output is correct |
48 |
Correct |
11 ms |
6772 KB |
Output is correct |
49 |
Correct |
10 ms |
7008 KB |
Output is correct |
50 |
Correct |
9 ms |
3288 KB |
Output is correct |
51 |
Correct |
0 ms |
344 KB |
Output is correct |
52 |
Correct |
0 ms |
344 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 |
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 |
604 KB |
Output is correct |
61 |
Correct |
0 ms |
604 KB |
Output is correct |
62 |
Correct |
0 ms |
604 KB |
Output is correct |
63 |
Correct |
0 ms |
604 KB |
Output is correct |
64 |
Correct |
1 ms |
860 KB |
Output is correct |
65 |
Correct |
13 ms |
5940 KB |
Output is correct |
66 |
Correct |
8 ms |
3288 KB |
Output is correct |
67 |
Correct |
11 ms |
3544 KB |
Output is correct |
68 |
Correct |
8 ms |
4056 KB |
Output is correct |
69 |
Correct |
11 ms |
7032 KB |
Output is correct |
70 |
Correct |
143 ms |
30864 KB |
Output is correct |
71 |
Correct |
1018 ms |
266892 KB |
Output is correct |
72 |
Correct |
1059 ms |
266892 KB |
Output is correct |
73 |
Correct |
571 ms |
121620 KB |
Output is correct |
74 |
Correct |
969 ms |
266124 KB |
Output is correct |
75 |
Correct |
640 ms |
126996 KB |
Output is correct |
76 |
Correct |
633 ms |
159888 KB |
Output is correct |
77 |
Correct |
612 ms |
149900 KB |
Output is correct |
78 |
Correct |
943 ms |
259172 KB |
Output is correct |
79 |
Correct |
1 ms |
348 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 |
344 KB |
Output is correct |
85 |
Correct |
0 ms |
344 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 |
14 ms |
6056 KB |
Output is correct |
91 |
Correct |
7 ms |
3284 KB |
Output is correct |
92 |
Correct |
8 ms |
3288 KB |
Output is correct |
93 |
Correct |
140 ms |
28828 KB |
Output is correct |
94 |
Correct |
515 ms |
122084 KB |
Output is correct |
95 |
Correct |
931 ms |
227472 KB |
Output is correct |
96 |
Correct |
982 ms |
216468 KB |
Output is correct |
97 |
Correct |
850 ms |
226144 KB |
Output is correct |
98 |
Correct |
559 ms |
122816 KB |
Output is correct |
99 |
Correct |
1039 ms |
263556 KB |
Output is correct |
100 |
Correct |
1057 ms |
265488 KB |
Output is correct |
101 |
Correct |
902 ms |
263816 KB |
Output is correct |
102 |
Correct |
878 ms |
265044 KB |
Output is correct |
103 |
Correct |
608 ms |
158560 KB |
Output is correct |
104 |
Correct |
849 ms |
254540 KB |
Output is correct |
105 |
Correct |
615 ms |
266896 KB |
Output is correct |