# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1019901 | 2024-07-11T10:27:51 Z | beaconmc | Fire (BOI24_fire) | C++14 | 223 ms | 95728 KB |
#include <bits/stdc++.h> typedef long long ll; #define FOR(i,x,y) for(ll i=x; i<y; i++) #define FORNEG(i,x,y) for(ll i=x; i>y; i--) using namespace std; vector<vector<ll>> normal; map<ll, ll> maxis; map<ll,ll> par; ll anc[100005][30]; ll ancc(ll x, ll k){ if (x==1000000000) return 1000000000; if (anc[x][k] != -1) return anc[x][k]; if (k==0){ if (par[x] == x) return anc[x][k] = 1000000000; return anc[x][k] = par[x]; } return anc[x][k] = ancc(ancc(x, k-1), k-1); } int main(){ FOR(i,0,100005) FOR(j,0,30) anc[i][j] = -1; ll n,m; cin >> n >> m; FOR(i,0,n){ ll a,b; cin >> a >> b; if (a<b) normal.push_back({a,b}); else normal.push_back({a,m+b}); } sort(normal.begin(), normal.end()); set<ll> things; for (auto&i : normal){ things.insert(i[0]); things.insert(i[1]); } ll cur = 0; ll maxi = -1; ll maxting = -1; for (auto&i : things){ while (cur < normal.size()){ if (normal[cur][0] <= i){ if (normal[cur][1] > maxi){ maxi = normal[cur][1]; maxting = cur; } }else break; cur++; } maxis[i] = maxting; } FOR(i,0,normal.size()){ par[i] = maxis[normal[i][1]]; } ll realans = 1000000000; FOR(i,0,normal.size()){ ll orig = normal[i][0]; ll ans = 0; ll lo = 0; ll hi = 10000000; while (lo < hi){ ll mid = (lo+hi)/2; ll idk = i; FOR(j,0,30){ if (mid&(1<<j)){ idk = ancc(idk, j); } } if (idk == 1000000000 || normal[idk][1] - orig >= m){ hi = mid; }else{ lo = mid+1; } } ll shit = i; FOR(j,0,30){ if (lo&(1<<j)){ shit = ancc(shit, j); } } if (shit < normal.size() && normal[shit][1] - orig >= m) realans = min(realans, lo+1); } if (realans == 1000000000) cout << -1 << endl; else cout << realans << endl; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 23900 KB | Output is correct |
2 | Correct | 4 ms | 23900 KB | Output is correct |
3 | Correct | 3 ms | 23900 KB | Output is correct |
4 | Correct | 4 ms | 23900 KB | Output is correct |
5 | Correct | 5 ms | 23736 KB | Output is correct |
6 | Correct | 4 ms | 23900 KB | Output is correct |
7 | Correct | 5 ms | 23844 KB | Output is correct |
8 | Correct | 4 ms | 23900 KB | Output is correct |
9 | Correct | 4 ms | 23900 KB | Output is correct |
10 | Correct | 4 ms | 23900 KB | Output is correct |
11 | Correct | 3 ms | 23900 KB | Output is correct |
12 | Correct | 4 ms | 23900 KB | Output is correct |
13 | Correct | 3 ms | 23900 KB | Output is correct |
14 | Correct | 3 ms | 23896 KB | Output is correct |
15 | Correct | 4 ms | 23900 KB | Output is correct |
16 | Correct | 4 ms | 23900 KB | Output is correct |
17 | Correct | 4 ms | 23792 KB | Output is correct |
18 | Correct | 3 ms | 23900 KB | Output is correct |
19 | Correct | 4 ms | 23900 KB | Output is correct |
20 | Correct | 3 ms | 23900 KB | Output is correct |
21 | Correct | 3 ms | 23900 KB | Output is correct |
22 | Correct | 3 ms | 23900 KB | Output is correct |
23 | Correct | 5 ms | 23900 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 23900 KB | Output is correct |
2 | Correct | 4 ms | 23900 KB | Output is correct |
3 | Correct | 3 ms | 23900 KB | Output is correct |
4 | Correct | 4 ms | 23900 KB | Output is correct |
5 | Correct | 5 ms | 23736 KB | Output is correct |
6 | Correct | 4 ms | 23900 KB | Output is correct |
7 | Correct | 5 ms | 23844 KB | Output is correct |
8 | Correct | 4 ms | 23900 KB | Output is correct |
9 | Correct | 4 ms | 23900 KB | Output is correct |
10 | Correct | 4 ms | 23900 KB | Output is correct |
11 | Correct | 3 ms | 23900 KB | Output is correct |
12 | Correct | 4 ms | 23900 KB | Output is correct |
13 | Correct | 3 ms | 23900 KB | Output is correct |
14 | Correct | 3 ms | 23896 KB | Output is correct |
15 | Correct | 4 ms | 23900 KB | Output is correct |
16 | Correct | 4 ms | 23900 KB | Output is correct |
17 | Correct | 4 ms | 23792 KB | Output is correct |
18 | Correct | 3 ms | 23900 KB | Output is correct |
19 | Correct | 4 ms | 23900 KB | Output is correct |
20 | Correct | 3 ms | 23900 KB | Output is correct |
21 | Correct | 3 ms | 23900 KB | Output is correct |
22 | Correct | 3 ms | 23900 KB | Output is correct |
23 | Correct | 5 ms | 23900 KB | Output is correct |
24 | Correct | 4 ms | 23900 KB | Output is correct |
25 | Correct | 4 ms | 23900 KB | Output is correct |
26 | Correct | 5 ms | 23900 KB | Output is correct |
27 | Correct | 4 ms | 23900 KB | Output is correct |
28 | Correct | 4 ms | 23900 KB | Output is correct |
29 | Correct | 4 ms | 23924 KB | Output is correct |
30 | Correct | 5 ms | 23900 KB | Output is correct |
31 | Correct | 4 ms | 23900 KB | Output is correct |
32 | Correct | 4 ms | 23976 KB | Output is correct |
33 | Correct | 5 ms | 23900 KB | Output is correct |
34 | Correct | 5 ms | 23900 KB | Output is correct |
35 | Correct | 5 ms | 23900 KB | Output is correct |
36 | Correct | 5 ms | 23900 KB | Output is correct |
37 | Correct | 4 ms | 23896 KB | Output is correct |
38 | Correct | 5 ms | 23936 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 23900 KB | Output is correct |
2 | Correct | 4 ms | 23900 KB | Output is correct |
3 | Correct | 3 ms | 23900 KB | Output is correct |
4 | Correct | 4 ms | 23900 KB | Output is correct |
5 | Correct | 5 ms | 23736 KB | Output is correct |
6 | Correct | 4 ms | 23900 KB | Output is correct |
7 | Correct | 5 ms | 23844 KB | Output is correct |
8 | Correct | 4 ms | 23900 KB | Output is correct |
9 | Correct | 4 ms | 23900 KB | Output is correct |
10 | Correct | 4 ms | 23900 KB | Output is correct |
11 | Correct | 3 ms | 23900 KB | Output is correct |
12 | Correct | 4 ms | 23900 KB | Output is correct |
13 | Correct | 3 ms | 23900 KB | Output is correct |
14 | Correct | 3 ms | 23896 KB | Output is correct |
15 | Correct | 4 ms | 23900 KB | Output is correct |
16 | Correct | 4 ms | 23900 KB | Output is correct |
17 | Correct | 4 ms | 23792 KB | Output is correct |
18 | Correct | 3 ms | 23900 KB | Output is correct |
19 | Correct | 4 ms | 23900 KB | Output is correct |
20 | Correct | 3 ms | 23900 KB | Output is correct |
21 | Correct | 3 ms | 23900 KB | Output is correct |
22 | Correct | 3 ms | 23900 KB | Output is correct |
23 | Correct | 5 ms | 23900 KB | Output is correct |
24 | Correct | 4 ms | 23900 KB | Output is correct |
25 | Correct | 4 ms | 23900 KB | Output is correct |
26 | Correct | 5 ms | 23900 KB | Output is correct |
27 | Correct | 4 ms | 23900 KB | Output is correct |
28 | Correct | 4 ms | 23900 KB | Output is correct |
29 | Correct | 4 ms | 23924 KB | Output is correct |
30 | Correct | 5 ms | 23900 KB | Output is correct |
31 | Correct | 4 ms | 23900 KB | Output is correct |
32 | Correct | 4 ms | 23976 KB | Output is correct |
33 | Correct | 5 ms | 23900 KB | Output is correct |
34 | Correct | 5 ms | 23900 KB | Output is correct |
35 | Correct | 5 ms | 23900 KB | Output is correct |
36 | Correct | 5 ms | 23900 KB | Output is correct |
37 | Correct | 4 ms | 23896 KB | Output is correct |
38 | Correct | 5 ms | 23936 KB | Output is correct |
39 | Correct | 17 ms | 25616 KB | Output is correct |
40 | Correct | 15 ms | 25616 KB | Output is correct |
41 | Correct | 16 ms | 25432 KB | Output is correct |
42 | Correct | 13 ms | 24924 KB | Output is correct |
43 | Correct | 12 ms | 24924 KB | Output is correct |
44 | Correct | 14 ms | 25072 KB | Output is correct |
45 | Correct | 17 ms | 24920 KB | Output is correct |
46 | Correct | 14 ms | 24924 KB | Output is correct |
47 | Correct | 16 ms | 25372 KB | Output is correct |
48 | Correct | 13 ms | 25436 KB | Output is correct |
49 | Correct | 14 ms | 25544 KB | Output is correct |
50 | Correct | 13 ms | 24924 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 23900 KB | Output is correct |
2 | Correct | 4 ms | 23900 KB | Output is correct |
3 | Correct | 4 ms | 23896 KB | Output is correct |
4 | Correct | 4 ms | 23896 KB | Output is correct |
5 | Correct | 4 ms | 23900 KB | Output is correct |
6 | Correct | 4 ms | 23900 KB | Output is correct |
7 | Correct | 4 ms | 23900 KB | Output is correct |
8 | Correct | 4 ms | 23900 KB | Output is correct |
9 | Correct | 4 ms | 23900 KB | Output is correct |
10 | Correct | 5 ms | 23896 KB | Output is correct |
11 | Correct | 4 ms | 23992 KB | Output is correct |
12 | Correct | 4 ms | 23900 KB | Output is correct |
13 | Correct | 3 ms | 23900 KB | Output is correct |
14 | Correct | 4 ms | 23896 KB | Output is correct |
15 | Correct | 15 ms | 25436 KB | Output is correct |
16 | Correct | 14 ms | 25024 KB | Output is correct |
17 | Correct | 12 ms | 24924 KB | Output is correct |
18 | Correct | 15 ms | 25072 KB | Output is correct |
19 | Correct | 14 ms | 25436 KB | Output is correct |
20 | Runtime error | 223 ms | 95564 KB | Execution killed with signal 11 |
21 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 23900 KB | Output is correct |
2 | Correct | 4 ms | 23884 KB | Output is correct |
3 | Correct | 3 ms | 23900 KB | Output is correct |
4 | Correct | 3 ms | 23900 KB | Output is correct |
5 | Correct | 3 ms | 23900 KB | Output is correct |
6 | Correct | 3 ms | 23900 KB | Output is correct |
7 | Correct | 4 ms | 23900 KB | Output is correct |
8 | Correct | 5 ms | 23900 KB | Output is correct |
9 | Correct | 6 ms | 24152 KB | Output is correct |
10 | Correct | 5 ms | 23900 KB | Output is correct |
11 | Correct | 4 ms | 23900 KB | Output is correct |
12 | Correct | 14 ms | 25600 KB | Output is correct |
13 | Correct | 18 ms | 25068 KB | Output is correct |
14 | Correct | 12 ms | 25072 KB | Output is correct |
15 | Runtime error | 214 ms | 95728 KB | Execution killed with signal 11 |
16 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 23900 KB | Output is correct |
2 | Correct | 4 ms | 23900 KB | Output is correct |
3 | Correct | 3 ms | 23900 KB | Output is correct |
4 | Correct | 4 ms | 23900 KB | Output is correct |
5 | Correct | 5 ms | 23736 KB | Output is correct |
6 | Correct | 4 ms | 23900 KB | Output is correct |
7 | Correct | 5 ms | 23844 KB | Output is correct |
8 | Correct | 4 ms | 23900 KB | Output is correct |
9 | Correct | 4 ms | 23900 KB | Output is correct |
10 | Correct | 4 ms | 23900 KB | Output is correct |
11 | Correct | 3 ms | 23900 KB | Output is correct |
12 | Correct | 4 ms | 23900 KB | Output is correct |
13 | Correct | 3 ms | 23900 KB | Output is correct |
14 | Correct | 3 ms | 23896 KB | Output is correct |
15 | Correct | 4 ms | 23900 KB | Output is correct |
16 | Correct | 4 ms | 23900 KB | Output is correct |
17 | Correct | 4 ms | 23792 KB | Output is correct |
18 | Correct | 3 ms | 23900 KB | Output is correct |
19 | Correct | 4 ms | 23900 KB | Output is correct |
20 | Correct | 3 ms | 23900 KB | Output is correct |
21 | Correct | 3 ms | 23900 KB | Output is correct |
22 | Correct | 3 ms | 23900 KB | Output is correct |
23 | Correct | 5 ms | 23900 KB | Output is correct |
24 | Correct | 4 ms | 23900 KB | Output is correct |
25 | Correct | 4 ms | 23900 KB | Output is correct |
26 | Correct | 5 ms | 23900 KB | Output is correct |
27 | Correct | 4 ms | 23900 KB | Output is correct |
28 | Correct | 4 ms | 23900 KB | Output is correct |
29 | Correct | 4 ms | 23924 KB | Output is correct |
30 | Correct | 5 ms | 23900 KB | Output is correct |
31 | Correct | 4 ms | 23900 KB | Output is correct |
32 | Correct | 4 ms | 23976 KB | Output is correct |
33 | Correct | 5 ms | 23900 KB | Output is correct |
34 | Correct | 5 ms | 23900 KB | Output is correct |
35 | Correct | 5 ms | 23900 KB | Output is correct |
36 | Correct | 5 ms | 23900 KB | Output is correct |
37 | Correct | 4 ms | 23896 KB | Output is correct |
38 | Correct | 5 ms | 23936 KB | Output is correct |
39 | Correct | 17 ms | 25616 KB | Output is correct |
40 | Correct | 15 ms | 25616 KB | Output is correct |
41 | Correct | 16 ms | 25432 KB | Output is correct |
42 | Correct | 13 ms | 24924 KB | Output is correct |
43 | Correct | 12 ms | 24924 KB | Output is correct |
44 | Correct | 14 ms | 25072 KB | Output is correct |
45 | Correct | 17 ms | 24920 KB | Output is correct |
46 | Correct | 14 ms | 24924 KB | Output is correct |
47 | Correct | 16 ms | 25372 KB | Output is correct |
48 | Correct | 13 ms | 25436 KB | Output is correct |
49 | Correct | 14 ms | 25544 KB | Output is correct |
50 | Correct | 13 ms | 24924 KB | Output is correct |
51 | Correct | 3 ms | 23900 KB | Output is correct |
52 | Correct | 4 ms | 23900 KB | Output is correct |
53 | Correct | 4 ms | 23896 KB | Output is correct |
54 | Correct | 4 ms | 23896 KB | Output is correct |
55 | Correct | 4 ms | 23900 KB | Output is correct |
56 | Correct | 4 ms | 23900 KB | Output is correct |
57 | Correct | 4 ms | 23900 KB | Output is correct |
58 | Correct | 4 ms | 23900 KB | Output is correct |
59 | Correct | 4 ms | 23900 KB | Output is correct |
60 | Correct | 5 ms | 23896 KB | Output is correct |
61 | Correct | 4 ms | 23992 KB | Output is correct |
62 | Correct | 4 ms | 23900 KB | Output is correct |
63 | Correct | 3 ms | 23900 KB | Output is correct |
64 | Correct | 4 ms | 23896 KB | Output is correct |
65 | Correct | 15 ms | 25436 KB | Output is correct |
66 | Correct | 14 ms | 25024 KB | Output is correct |
67 | Correct | 12 ms | 24924 KB | Output is correct |
68 | Correct | 15 ms | 25072 KB | Output is correct |
69 | Correct | 14 ms | 25436 KB | Output is correct |
70 | Runtime error | 223 ms | 95564 KB | Execution killed with signal 11 |
71 | Halted | 0 ms | 0 KB | - |