Submission #1027519

# Submission time Handle Problem Language Result Execution time Memory
1027519 2024-07-19T07:12:57 Z mansur Fire (BOI24_fire) C++17
40 / 100
117 ms 39116 KB
#include<bits/stdc++.h>

using namespace std;

#define rall(s) s.rbegin(), s.rend()
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define s second
#define f first

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int N = 1e6;
const int inf = 1e9;

int lg[N], up[N][20];

void solve() {
	int n, m;
	cin >> n >> m;
	int cur = n + 1;
	vector<int> l(n + 1), r(n + 1);
	vector<array<int, 3>> s;
	for (int i = 1; i <= n; i++) {
		cin >> l[i] >> r[i];
		if (r[i] < l[i]) {
			r[i] += m;
			s.push_back({l[i], 0, i});
			s.push_back({r[i], 1, i});
		}else {
			s.push_back({l[i], 0, i});
			s.push_back({r[i], 1, i});
			l.push_back(l[i] + m);
			r.push_back(r[i] + m);
			s.push_back({l[cur], 0, cur});
			s.push_back({r[cur], 1, cur});
			cur++;
		}
	}
	n = cur - 1;
	sort(all(s));
	int mx = -1, vt;
	for (auto [p, is, id]: s) {
		if (!is) {
			if (r[id] > mx) {
			 	mx = r[id];
			 	vt = id;
			}
		}else up[id][0] = vt;
	}
	for (int k = 1; k <= lg[n]; k++) {
		for (int i = 1; i <= n; i++) {
			up[i][k] = up[up[i][k - 1]][k - 1];			
		}
	}
	int mn = inf;
	for (int i = 1; i <= n; i++) {
		if (r[i] - l[i] + 1 >= m) {
			mn = 1;
			break;
		}
		int tl = l[i], v = i, ans = 2;
		for (int k = lg[n]; k >= 0; k--) {
            int tr = r[up[v][k]];
            if (tr - tl + 1 >= m) continue;
            v = up[v][k];
            ans += (1 << k);
        }
        v = up[v][0];              
        if (r[v] - tl + 1 < m) continue;
        mn = min(mn, ans);
	}
	if (mn > n) cout << -1;
	else cout << mn;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	for (int i = 1; i < N; i++) lg[i] = lg[i / 2] + 1;
	solve();
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:51:19: warning: 'vt' may be used uninitialized in this function [-Wmaybe-uninitialized]
   51 |   }else up[id][0] = vt;
      |         ~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4184 KB Output is correct
2 Correct 3 ms 4188 KB Output is correct
3 Correct 3 ms 4188 KB Output is correct
4 Correct 2 ms 4188 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
6 Correct 3 ms 4188 KB Output is correct
7 Correct 2 ms 4156 KB Output is correct
8 Correct 3 ms 4188 KB Output is correct
9 Correct 5 ms 4444 KB Output is correct
10 Correct 4 ms 4188 KB Output is correct
11 Correct 4 ms 4188 KB Output is correct
12 Correct 3 ms 4188 KB Output is correct
13 Correct 2 ms 4188 KB Output is correct
14 Correct 2 ms 4188 KB Output is correct
15 Correct 2 ms 4188 KB Output is correct
16 Correct 4 ms 4184 KB Output is correct
17 Correct 3 ms 4188 KB Output is correct
18 Correct 3 ms 4188 KB Output is correct
19 Correct 3 ms 4188 KB Output is correct
20 Correct 2 ms 4292 KB Output is correct
21 Correct 2 ms 4188 KB Output is correct
22 Correct 3 ms 4188 KB Output is correct
23 Correct 2 ms 4188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4184 KB Output is correct
2 Correct 3 ms 4188 KB Output is correct
3 Correct 3 ms 4188 KB Output is correct
4 Correct 2 ms 4188 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
6 Correct 3 ms 4188 KB Output is correct
7 Correct 2 ms 4156 KB Output is correct
8 Correct 3 ms 4188 KB Output is correct
9 Correct 5 ms 4444 KB Output is correct
10 Correct 4 ms 4188 KB Output is correct
11 Correct 4 ms 4188 KB Output is correct
12 Correct 3 ms 4188 KB Output is correct
13 Correct 2 ms 4188 KB Output is correct
14 Correct 2 ms 4188 KB Output is correct
15 Correct 2 ms 4188 KB Output is correct
16 Correct 4 ms 4184 KB Output is correct
17 Correct 3 ms 4188 KB Output is correct
18 Correct 3 ms 4188 KB Output is correct
19 Correct 3 ms 4188 KB Output is correct
20 Correct 2 ms 4292 KB Output is correct
21 Correct 2 ms 4188 KB Output is correct
22 Correct 3 ms 4188 KB Output is correct
23 Correct 2 ms 4188 KB Output is correct
24 Correct 3 ms 4184 KB Output is correct
25 Correct 3 ms 4444 KB Output is correct
26 Correct 3 ms 4444 KB Output is correct
27 Correct 3 ms 4440 KB Output is correct
28 Correct 3 ms 4444 KB Output is correct
29 Correct 3 ms 4440 KB Output is correct
30 Correct 3 ms 4444 KB Output is correct
31 Correct 2 ms 4444 KB Output is correct
32 Correct 2 ms 4444 KB Output is correct
33 Correct 3 ms 4444 KB Output is correct
34 Correct 3 ms 4444 KB Output is correct
35 Correct 3 ms 4444 KB Output is correct
36 Correct 2 ms 4444 KB Output is correct
37 Correct 4 ms 4228 KB Output is correct
38 Correct 3 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4184 KB Output is correct
2 Correct 3 ms 4188 KB Output is correct
3 Correct 3 ms 4188 KB Output is correct
4 Correct 2 ms 4188 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
6 Correct 3 ms 4188 KB Output is correct
7 Correct 2 ms 4156 KB Output is correct
8 Correct 3 ms 4188 KB Output is correct
9 Correct 5 ms 4444 KB Output is correct
10 Correct 4 ms 4188 KB Output is correct
11 Correct 4 ms 4188 KB Output is correct
12 Correct 3 ms 4188 KB Output is correct
13 Correct 2 ms 4188 KB Output is correct
14 Correct 2 ms 4188 KB Output is correct
15 Correct 2 ms 4188 KB Output is correct
16 Correct 4 ms 4184 KB Output is correct
17 Correct 3 ms 4188 KB Output is correct
18 Correct 3 ms 4188 KB Output is correct
19 Correct 3 ms 4188 KB Output is correct
20 Correct 2 ms 4292 KB Output is correct
21 Correct 2 ms 4188 KB Output is correct
22 Correct 3 ms 4188 KB Output is correct
23 Correct 2 ms 4188 KB Output is correct
24 Correct 3 ms 4184 KB Output is correct
25 Correct 3 ms 4444 KB Output is correct
26 Correct 3 ms 4444 KB Output is correct
27 Correct 3 ms 4440 KB Output is correct
28 Correct 3 ms 4444 KB Output is correct
29 Correct 3 ms 4440 KB Output is correct
30 Correct 3 ms 4444 KB Output is correct
31 Correct 2 ms 4444 KB Output is correct
32 Correct 2 ms 4444 KB Output is correct
33 Correct 3 ms 4444 KB Output is correct
34 Correct 3 ms 4444 KB Output is correct
35 Correct 3 ms 4444 KB Output is correct
36 Correct 2 ms 4444 KB Output is correct
37 Correct 4 ms 4228 KB Output is correct
38 Correct 3 ms 4444 KB Output is correct
39 Correct 5 ms 7024 KB Output is correct
40 Correct 5 ms 7024 KB Output is correct
41 Correct 9 ms 7024 KB Output is correct
42 Correct 6 ms 7024 KB Output is correct
43 Correct 7 ms 6816 KB Output is correct
44 Correct 6 ms 7024 KB Output is correct
45 Correct 6 ms 7024 KB Output is correct
46 Correct 6 ms 6832 KB Output is correct
47 Correct 5 ms 7024 KB Output is correct
48 Correct 6 ms 7024 KB Output is correct
49 Correct 8 ms 7024 KB Output is correct
50 Correct 6 ms 7024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4188 KB Output is correct
2 Correct 2 ms 4188 KB Output is correct
3 Correct 3 ms 4184 KB Output is correct
4 Correct 3 ms 4188 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
6 Correct 2 ms 4188 KB Output is correct
7 Correct 3 ms 4188 KB Output is correct
8 Correct 3 ms 4184 KB Output is correct
9 Correct 3 ms 4444 KB Output is correct
10 Correct 3 ms 4444 KB Output is correct
11 Correct 3 ms 4444 KB Output is correct
12 Correct 5 ms 4440 KB Output is correct
13 Correct 5 ms 4440 KB Output is correct
14 Correct 3 ms 4376 KB Output is correct
15 Correct 6 ms 6916 KB Output is correct
16 Correct 6 ms 7020 KB Output is correct
17 Correct 8 ms 7024 KB Output is correct
18 Correct 6 ms 7024 KB Output is correct
19 Correct 5 ms 7024 KB Output is correct
20 Incorrect 117 ms 39116 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4184 KB Output is correct
2 Correct 3 ms 4184 KB Output is correct
3 Correct 2 ms 4188 KB Output is correct
4 Correct 4 ms 4188 KB Output is correct
5 Correct 3 ms 4188 KB Output is correct
6 Correct 3 ms 4188 KB Output is correct
7 Correct 2 ms 4188 KB Output is correct
8 Correct 3 ms 4452 KB Output is correct
9 Correct 3 ms 4444 KB Output is correct
10 Correct 3 ms 4444 KB Output is correct
11 Correct 3 ms 4444 KB Output is correct
12 Correct 7 ms 6924 KB Output is correct
13 Correct 6 ms 7024 KB Output is correct
14 Correct 9 ms 7020 KB Output is correct
15 Incorrect 110 ms 38924 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4184 KB Output is correct
2 Correct 3 ms 4188 KB Output is correct
3 Correct 3 ms 4188 KB Output is correct
4 Correct 2 ms 4188 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
6 Correct 3 ms 4188 KB Output is correct
7 Correct 2 ms 4156 KB Output is correct
8 Correct 3 ms 4188 KB Output is correct
9 Correct 5 ms 4444 KB Output is correct
10 Correct 4 ms 4188 KB Output is correct
11 Correct 4 ms 4188 KB Output is correct
12 Correct 3 ms 4188 KB Output is correct
13 Correct 2 ms 4188 KB Output is correct
14 Correct 2 ms 4188 KB Output is correct
15 Correct 2 ms 4188 KB Output is correct
16 Correct 4 ms 4184 KB Output is correct
17 Correct 3 ms 4188 KB Output is correct
18 Correct 3 ms 4188 KB Output is correct
19 Correct 3 ms 4188 KB Output is correct
20 Correct 2 ms 4292 KB Output is correct
21 Correct 2 ms 4188 KB Output is correct
22 Correct 3 ms 4188 KB Output is correct
23 Correct 2 ms 4188 KB Output is correct
24 Correct 3 ms 4184 KB Output is correct
25 Correct 3 ms 4444 KB Output is correct
26 Correct 3 ms 4444 KB Output is correct
27 Correct 3 ms 4440 KB Output is correct
28 Correct 3 ms 4444 KB Output is correct
29 Correct 3 ms 4440 KB Output is correct
30 Correct 3 ms 4444 KB Output is correct
31 Correct 2 ms 4444 KB Output is correct
32 Correct 2 ms 4444 KB Output is correct
33 Correct 3 ms 4444 KB Output is correct
34 Correct 3 ms 4444 KB Output is correct
35 Correct 3 ms 4444 KB Output is correct
36 Correct 2 ms 4444 KB Output is correct
37 Correct 4 ms 4228 KB Output is correct
38 Correct 3 ms 4444 KB Output is correct
39 Correct 5 ms 7024 KB Output is correct
40 Correct 5 ms 7024 KB Output is correct
41 Correct 9 ms 7024 KB Output is correct
42 Correct 6 ms 7024 KB Output is correct
43 Correct 7 ms 6816 KB Output is correct
44 Correct 6 ms 7024 KB Output is correct
45 Correct 6 ms 7024 KB Output is correct
46 Correct 6 ms 6832 KB Output is correct
47 Correct 5 ms 7024 KB Output is correct
48 Correct 6 ms 7024 KB Output is correct
49 Correct 8 ms 7024 KB Output is correct
50 Correct 6 ms 7024 KB Output is correct
51 Correct 3 ms 4188 KB Output is correct
52 Correct 2 ms 4188 KB Output is correct
53 Correct 3 ms 4184 KB Output is correct
54 Correct 3 ms 4188 KB Output is correct
55 Correct 2 ms 4188 KB Output is correct
56 Correct 2 ms 4188 KB Output is correct
57 Correct 3 ms 4188 KB Output is correct
58 Correct 3 ms 4184 KB Output is correct
59 Correct 3 ms 4444 KB Output is correct
60 Correct 3 ms 4444 KB Output is correct
61 Correct 3 ms 4444 KB Output is correct
62 Correct 5 ms 4440 KB Output is correct
63 Correct 5 ms 4440 KB Output is correct
64 Correct 3 ms 4376 KB Output is correct
65 Correct 6 ms 6916 KB Output is correct
66 Correct 6 ms 7020 KB Output is correct
67 Correct 8 ms 7024 KB Output is correct
68 Correct 6 ms 7024 KB Output is correct
69 Correct 5 ms 7024 KB Output is correct
70 Incorrect 117 ms 39116 KB Output isn't correct
71 Halted 0 ms 0 KB -