# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1000750 |
2024-06-18T08:17:51 Z |
dilanyan |
Fire (BOI24_fire) |
C++17 |
|
181 ms |
23924 KB |
//-------------dilanyan------------\\
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
//------------------Kargpefines--------------------\\
#define ll long long
#define pb push_back
#define all(u) (u).begin(), (u).end()
#define pqueue priority_queue
#define upper upper_bound
#define lower lower_bound
#define umap unordered_map
#define uset unordered_set
void KarginSet(string name = "") {
ios_base::sync_with_stdio(false); cin.tie(NULL);
if (name.size()) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
}
//-------------------KarginConstants------------------\\
const ll mod = 1e9 + 7;
const ll inf = 1e9;
//-------------------KarginCode-----------------------\\
const int N = 200005, M = 1000005;
int n, m;
pair<int, int> a[N];
int tree[4 * N], ind[4 * N];
struct segtree {
int size = 1;
void init() {
while (size < n) size <<= 1;
build(0, 0, size);
}
void build(int x, int lx, int rx) {
if (rx - lx == 1) {
if (lx < n) {
tree[x] = a[lx].second;
ind[x] = lx;
}
return;
}
int m = (lx + rx) / 2;
build(2 * x + 1, lx, m);
build(2 * x + 2, m, rx);
if (tree[2 * x + 1] > tree[2 * x + 2]) tree[x] = tree[2 * x + 1], ind[x] = ind[2 * x + 1];
else tree[x] = tree[2 * x + 2], ind[x] = ind[2 * x + 2];
}
pair<int,int> get(int l, int r, int x, int lx, int rx) {
if (lx >= r || rx <= l) return make_pair(0, 0);
if (lx >= l && rx <= r) return make_pair(tree[x], ind[x]);
int m = (lx + rx) / 2;
pair<int,int> getl = get(l, r, 2 * x + 1, lx, m),
getr = get(l, r, 2 * x + 2, m, rx);
if (getl.first > getr.first) return getl;
return getr;
}
int get(int l, int r) {
return get(l, r, 0, 0, size).second;
}
};
int up[N][20];
void KarginSolve() {
cin >> n >> m;
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, a + n);
segtree st;
st.init();
for (int i = 0; i < n;i++) {
int l = i, r = n - 1, indx = n;
while (l <= r) {
int mid = (l + r) / 2;
if (a[mid].first > a[i].second) {
r = mid - 1;
indx = mid;
}
else l = mid + 1;
}
up[i][0] = st.get(i, indx);
}
for (int j = 1;j < 20;j++) {
for (int i = 0;i < n;i++) {
up[i][j] = up[up[i][j - 1]][j - 1];
}
}
int ans = inf;
for (int i = 0;i < n;i++) {
int l = 0, r = n - 1, res = inf;
while (l <= r) {
int mid = (l + r) / 2;
int x = i;
for (int j = 0;j < 20;j++) {
if (mid & (1 << j)) x = up[x][j];
}
if (a[x].second >= a[i].first + m) {
r = mid - 1;
res = mid;
}
else {
l = mid + 1;
}
}
ans = min(ans, res + 1);
}
if (ans == inf) cout << -1 << '\n';
else cout << ans << '\n';
}
int main() {
KarginSet();
int test = 1;
//cin >> test;
while (test--) {
KarginSolve();
}
return 0;
}
Compilation message
Main.cpp:1:1: warning: multi-line comment [-Wcomment]
1 | //-------------dilanyan------------\\
| ^
Main.cpp:8:1: warning: multi-line comment [-Wcomment]
8 | //------------------Kargpefines--------------------\\
| ^
Main.cpp:27:1: warning: multi-line comment [-Wcomment]
27 | //-------------------KarginConstants------------------\\
| ^
Main.cpp:32:1: warning: multi-line comment [-Wcomment]
32 | //-------------------KarginCode-----------------------\\
| ^
Main.cpp: In function 'void KarginSet(std::string)':
Main.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | freopen((name + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | freopen((name + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
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 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6556 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
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 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6556 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
1 ms |
6492 KB |
Output is correct |
25 |
Correct |
1 ms |
6492 KB |
Output is correct |
26 |
Correct |
1 ms |
6492 KB |
Output is correct |
27 |
Correct |
1 ms |
6492 KB |
Output is correct |
28 |
Correct |
1 ms |
6492 KB |
Output is correct |
29 |
Correct |
1 ms |
6492 KB |
Output is correct |
30 |
Correct |
1 ms |
6492 KB |
Output is correct |
31 |
Correct |
1 ms |
6492 KB |
Output is correct |
32 |
Correct |
1 ms |
6492 KB |
Output is correct |
33 |
Correct |
1 ms |
6492 KB |
Output is correct |
34 |
Correct |
1 ms |
6492 KB |
Output is correct |
35 |
Correct |
1 ms |
6492 KB |
Output is correct |
36 |
Correct |
1 ms |
6492 KB |
Output is correct |
37 |
Correct |
1 ms |
6492 KB |
Output is correct |
38 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
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 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6556 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
1 ms |
6492 KB |
Output is correct |
25 |
Correct |
1 ms |
6492 KB |
Output is correct |
26 |
Correct |
1 ms |
6492 KB |
Output is correct |
27 |
Correct |
1 ms |
6492 KB |
Output is correct |
28 |
Correct |
1 ms |
6492 KB |
Output is correct |
29 |
Correct |
1 ms |
6492 KB |
Output is correct |
30 |
Correct |
1 ms |
6492 KB |
Output is correct |
31 |
Correct |
1 ms |
6492 KB |
Output is correct |
32 |
Correct |
1 ms |
6492 KB |
Output is correct |
33 |
Correct |
1 ms |
6492 KB |
Output is correct |
34 |
Correct |
1 ms |
6492 KB |
Output is correct |
35 |
Correct |
1 ms |
6492 KB |
Output is correct |
36 |
Correct |
1 ms |
6492 KB |
Output is correct |
37 |
Correct |
1 ms |
6492 KB |
Output is correct |
38 |
Correct |
1 ms |
6492 KB |
Output is correct |
39 |
Correct |
4 ms |
7000 KB |
Output is correct |
40 |
Correct |
3 ms |
7004 KB |
Output is correct |
41 |
Correct |
4 ms |
8796 KB |
Output is correct |
42 |
Correct |
3 ms |
7004 KB |
Output is correct |
43 |
Correct |
4 ms |
8840 KB |
Output is correct |
44 |
Correct |
3 ms |
7004 KB |
Output is correct |
45 |
Correct |
3 ms |
7004 KB |
Output is correct |
46 |
Correct |
5 ms |
8796 KB |
Output is correct |
47 |
Correct |
4 ms |
7004 KB |
Output is correct |
48 |
Correct |
3 ms |
8796 KB |
Output is correct |
49 |
Correct |
3 ms |
8796 KB |
Output is correct |
50 |
Correct |
4 ms |
6872 KB |
Output is correct |
# |
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 |
6496 KB |
Output is correct |
5 |
Correct |
1 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
6496 KB |
Output is correct |
7 |
Correct |
1 ms |
6488 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6616 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
3 ms |
8796 KB |
Output is correct |
16 |
Correct |
3 ms |
7004 KB |
Output is correct |
17 |
Correct |
4 ms |
7004 KB |
Output is correct |
18 |
Correct |
3 ms |
8844 KB |
Output is correct |
19 |
Correct |
3 ms |
8840 KB |
Output is correct |
20 |
Correct |
116 ms |
23844 KB |
Output is correct |
21 |
Correct |
164 ms |
23884 KB |
Output is correct |
22 |
Correct |
155 ms |
23812 KB |
Output is correct |
23 |
Correct |
138 ms |
23752 KB |
Output is correct |
24 |
Correct |
146 ms |
23732 KB |
Output is correct |
25 |
Correct |
162 ms |
23888 KB |
Output is correct |
26 |
Correct |
131 ms |
23912 KB |
Output is correct |
27 |
Correct |
143 ms |
23888 KB |
Output is correct |
28 |
Correct |
133 ms |
23728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 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 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
4 ms |
8796 KB |
Output is correct |
13 |
Correct |
3 ms |
7004 KB |
Output is correct |
14 |
Correct |
3 ms |
7004 KB |
Output is correct |
15 |
Correct |
111 ms |
23892 KB |
Output is correct |
16 |
Correct |
144 ms |
23924 KB |
Output is correct |
17 |
Correct |
155 ms |
23708 KB |
Output is correct |
18 |
Correct |
161 ms |
23888 KB |
Output is correct |
19 |
Correct |
152 ms |
23756 KB |
Output is correct |
20 |
Correct |
164 ms |
23888 KB |
Output is correct |
# |
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 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6556 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
6492 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
1 ms |
6492 KB |
Output is correct |
25 |
Correct |
1 ms |
6492 KB |
Output is correct |
26 |
Correct |
1 ms |
6492 KB |
Output is correct |
27 |
Correct |
1 ms |
6492 KB |
Output is correct |
28 |
Correct |
1 ms |
6492 KB |
Output is correct |
29 |
Correct |
1 ms |
6492 KB |
Output is correct |
30 |
Correct |
1 ms |
6492 KB |
Output is correct |
31 |
Correct |
1 ms |
6492 KB |
Output is correct |
32 |
Correct |
1 ms |
6492 KB |
Output is correct |
33 |
Correct |
1 ms |
6492 KB |
Output is correct |
34 |
Correct |
1 ms |
6492 KB |
Output is correct |
35 |
Correct |
1 ms |
6492 KB |
Output is correct |
36 |
Correct |
1 ms |
6492 KB |
Output is correct |
37 |
Correct |
1 ms |
6492 KB |
Output is correct |
38 |
Correct |
1 ms |
6492 KB |
Output is correct |
39 |
Correct |
4 ms |
7000 KB |
Output is correct |
40 |
Correct |
3 ms |
7004 KB |
Output is correct |
41 |
Correct |
4 ms |
8796 KB |
Output is correct |
42 |
Correct |
3 ms |
7004 KB |
Output is correct |
43 |
Correct |
4 ms |
8840 KB |
Output is correct |
44 |
Correct |
3 ms |
7004 KB |
Output is correct |
45 |
Correct |
3 ms |
7004 KB |
Output is correct |
46 |
Correct |
5 ms |
8796 KB |
Output is correct |
47 |
Correct |
4 ms |
7004 KB |
Output is correct |
48 |
Correct |
3 ms |
8796 KB |
Output is correct |
49 |
Correct |
3 ms |
8796 KB |
Output is correct |
50 |
Correct |
4 ms |
6872 KB |
Output is correct |
51 |
Correct |
1 ms |
6492 KB |
Output is correct |
52 |
Correct |
1 ms |
6492 KB |
Output is correct |
53 |
Correct |
1 ms |
6492 KB |
Output is correct |
54 |
Correct |
1 ms |
6496 KB |
Output is correct |
55 |
Correct |
1 ms |
6488 KB |
Output is correct |
56 |
Correct |
1 ms |
6496 KB |
Output is correct |
57 |
Correct |
1 ms |
6488 KB |
Output is correct |
58 |
Correct |
1 ms |
6492 KB |
Output is correct |
59 |
Correct |
1 ms |
6492 KB |
Output is correct |
60 |
Correct |
1 ms |
6492 KB |
Output is correct |
61 |
Correct |
1 ms |
6616 KB |
Output is correct |
62 |
Correct |
1 ms |
6492 KB |
Output is correct |
63 |
Correct |
1 ms |
6492 KB |
Output is correct |
64 |
Correct |
1 ms |
6492 KB |
Output is correct |
65 |
Correct |
3 ms |
8796 KB |
Output is correct |
66 |
Correct |
3 ms |
7004 KB |
Output is correct |
67 |
Correct |
4 ms |
7004 KB |
Output is correct |
68 |
Correct |
3 ms |
8844 KB |
Output is correct |
69 |
Correct |
3 ms |
8840 KB |
Output is correct |
70 |
Correct |
116 ms |
23844 KB |
Output is correct |
71 |
Correct |
164 ms |
23884 KB |
Output is correct |
72 |
Correct |
155 ms |
23812 KB |
Output is correct |
73 |
Correct |
138 ms |
23752 KB |
Output is correct |
74 |
Correct |
146 ms |
23732 KB |
Output is correct |
75 |
Correct |
162 ms |
23888 KB |
Output is correct |
76 |
Correct |
131 ms |
23912 KB |
Output is correct |
77 |
Correct |
143 ms |
23888 KB |
Output is correct |
78 |
Correct |
133 ms |
23728 KB |
Output is correct |
79 |
Correct |
1 ms |
6488 KB |
Output is correct |
80 |
Correct |
1 ms |
6492 KB |
Output is correct |
81 |
Correct |
1 ms |
6492 KB |
Output is correct |
82 |
Correct |
1 ms |
6492 KB |
Output is correct |
83 |
Correct |
1 ms |
6492 KB |
Output is correct |
84 |
Correct |
1 ms |
6492 KB |
Output is correct |
85 |
Correct |
1 ms |
6492 KB |
Output is correct |
86 |
Correct |
1 ms |
6492 KB |
Output is correct |
87 |
Correct |
1 ms |
6492 KB |
Output is correct |
88 |
Correct |
1 ms |
6492 KB |
Output is correct |
89 |
Correct |
1 ms |
6492 KB |
Output is correct |
90 |
Correct |
4 ms |
8796 KB |
Output is correct |
91 |
Correct |
3 ms |
7004 KB |
Output is correct |
92 |
Correct |
3 ms |
7004 KB |
Output is correct |
93 |
Correct |
111 ms |
23892 KB |
Output is correct |
94 |
Correct |
144 ms |
23924 KB |
Output is correct |
95 |
Correct |
155 ms |
23708 KB |
Output is correct |
96 |
Correct |
161 ms |
23888 KB |
Output is correct |
97 |
Correct |
152 ms |
23756 KB |
Output is correct |
98 |
Correct |
164 ms |
23888 KB |
Output is correct |
99 |
Correct |
140 ms |
23888 KB |
Output is correct |
100 |
Correct |
152 ms |
23784 KB |
Output is correct |
101 |
Correct |
147 ms |
23800 KB |
Output is correct |
102 |
Correct |
181 ms |
23832 KB |
Output is correct |
103 |
Correct |
146 ms |
23892 KB |
Output is correct |
104 |
Correct |
136 ms |
23920 KB |
Output is correct |
105 |
Correct |
144 ms |
23688 KB |
Output is correct |