# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1019905 | 2024-07-11T10:30:02 Z | beaconmc | Fire (BOI24_fire) | C++14 | 1145 ms | 189240 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[500005][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,500005) 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 62 ms | 117776 KB | Output is correct |
2 | Correct | 53 ms | 117588 KB | Output is correct |
3 | Correct | 57 ms | 117584 KB | Output is correct |
4 | Correct | 54 ms | 117584 KB | Output is correct |
5 | Correct | 56 ms | 117852 KB | Output is correct |
6 | Correct | 55 ms | 117588 KB | Output is correct |
7 | Correct | 66 ms | 117720 KB | Output is correct |
8 | Correct | 62 ms | 117676 KB | Output is correct |
9 | Correct | 55 ms | 117788 KB | Output is correct |
10 | Correct | 54 ms | 117840 KB | Output is correct |
11 | Correct | 57 ms | 117840 KB | Output is correct |
12 | Correct | 54 ms | 117588 KB | Output is correct |
13 | Correct | 54 ms | 117656 KB | Output is correct |
14 | Correct | 55 ms | 117840 KB | Output is correct |
15 | Correct | 52 ms | 117588 KB | Output is correct |
16 | Correct | 56 ms | 117588 KB | Output is correct |
17 | Correct | 56 ms | 117632 KB | Output is correct |
18 | Correct | 61 ms | 117588 KB | Output is correct |
19 | Correct | 55 ms | 117588 KB | Output is correct |
20 | Correct | 56 ms | 117588 KB | Output is correct |
21 | Correct | 58 ms | 117588 KB | Output is correct |
22 | Correct | 54 ms | 117704 KB | Output is correct |
23 | Correct | 62 ms | 117728 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 62 ms | 117776 KB | Output is correct |
2 | Correct | 53 ms | 117588 KB | Output is correct |
3 | Correct | 57 ms | 117584 KB | Output is correct |
4 | Correct | 54 ms | 117584 KB | Output is correct |
5 | Correct | 56 ms | 117852 KB | Output is correct |
6 | Correct | 55 ms | 117588 KB | Output is correct |
7 | Correct | 66 ms | 117720 KB | Output is correct |
8 | Correct | 62 ms | 117676 KB | Output is correct |
9 | Correct | 55 ms | 117788 KB | Output is correct |
10 | Correct | 54 ms | 117840 KB | Output is correct |
11 | Correct | 57 ms | 117840 KB | Output is correct |
12 | Correct | 54 ms | 117588 KB | Output is correct |
13 | Correct | 54 ms | 117656 KB | Output is correct |
14 | Correct | 55 ms | 117840 KB | Output is correct |
15 | Correct | 52 ms | 117588 KB | Output is correct |
16 | Correct | 56 ms | 117588 KB | Output is correct |
17 | Correct | 56 ms | 117632 KB | Output is correct |
18 | Correct | 61 ms | 117588 KB | Output is correct |
19 | Correct | 55 ms | 117588 KB | Output is correct |
20 | Correct | 56 ms | 117588 KB | Output is correct |
21 | Correct | 58 ms | 117588 KB | Output is correct |
22 | Correct | 54 ms | 117704 KB | Output is correct |
23 | Correct | 62 ms | 117728 KB | Output is correct |
24 | Correct | 59 ms | 117752 KB | Output is correct |
25 | Correct | 53 ms | 117844 KB | Output is correct |
26 | Correct | 54 ms | 117840 KB | Output is correct |
27 | Correct | 53 ms | 117844 KB | Output is correct |
28 | Correct | 52 ms | 117840 KB | Output is correct |
29 | Correct | 54 ms | 117840 KB | Output is correct |
30 | Correct | 52 ms | 117844 KB | Output is correct |
31 | Correct | 53 ms | 117844 KB | Output is correct |
32 | Correct | 54 ms | 117816 KB | Output is correct |
33 | Correct | 53 ms | 117660 KB | Output is correct |
34 | Correct | 56 ms | 117788 KB | Output is correct |
35 | Correct | 55 ms | 117840 KB | Output is correct |
36 | Correct | 57 ms | 117848 KB | Output is correct |
37 | Correct | 53 ms | 117800 KB | Output is correct |
38 | Correct | 53 ms | 117852 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 62 ms | 117776 KB | Output is correct |
2 | Correct | 53 ms | 117588 KB | Output is correct |
3 | Correct | 57 ms | 117584 KB | Output is correct |
4 | Correct | 54 ms | 117584 KB | Output is correct |
5 | Correct | 56 ms | 117852 KB | Output is correct |
6 | Correct | 55 ms | 117588 KB | Output is correct |
7 | Correct | 66 ms | 117720 KB | Output is correct |
8 | Correct | 62 ms | 117676 KB | Output is correct |
9 | Correct | 55 ms | 117788 KB | Output is correct |
10 | Correct | 54 ms | 117840 KB | Output is correct |
11 | Correct | 57 ms | 117840 KB | Output is correct |
12 | Correct | 54 ms | 117588 KB | Output is correct |
13 | Correct | 54 ms | 117656 KB | Output is correct |
14 | Correct | 55 ms | 117840 KB | Output is correct |
15 | Correct | 52 ms | 117588 KB | Output is correct |
16 | Correct | 56 ms | 117588 KB | Output is correct |
17 | Correct | 56 ms | 117632 KB | Output is correct |
18 | Correct | 61 ms | 117588 KB | Output is correct |
19 | Correct | 55 ms | 117588 KB | Output is correct |
20 | Correct | 56 ms | 117588 KB | Output is correct |
21 | Correct | 58 ms | 117588 KB | Output is correct |
22 | Correct | 54 ms | 117704 KB | Output is correct |
23 | Correct | 62 ms | 117728 KB | Output is correct |
24 | Correct | 59 ms | 117752 KB | Output is correct |
25 | Correct | 53 ms | 117844 KB | Output is correct |
26 | Correct | 54 ms | 117840 KB | Output is correct |
27 | Correct | 53 ms | 117844 KB | Output is correct |
28 | Correct | 52 ms | 117840 KB | Output is correct |
29 | Correct | 54 ms | 117840 KB | Output is correct |
30 | Correct | 52 ms | 117844 KB | Output is correct |
31 | Correct | 53 ms | 117844 KB | Output is correct |
32 | Correct | 54 ms | 117816 KB | Output is correct |
33 | Correct | 53 ms | 117660 KB | Output is correct |
34 | Correct | 56 ms | 117788 KB | Output is correct |
35 | Correct | 55 ms | 117840 KB | Output is correct |
36 | Correct | 57 ms | 117848 KB | Output is correct |
37 | Correct | 53 ms | 117800 KB | Output is correct |
38 | Correct | 53 ms | 117852 KB | Output is correct |
39 | Correct | 63 ms | 119376 KB | Output is correct |
40 | Correct | 80 ms | 119432 KB | Output is correct |
41 | Correct | 69 ms | 119380 KB | Output is correct |
42 | Correct | 64 ms | 118868 KB | Output is correct |
43 | Correct | 60 ms | 118864 KB | Output is correct |
44 | Correct | 61 ms | 118784 KB | Output is correct |
45 | Correct | 63 ms | 118868 KB | Output is correct |
46 | Correct | 72 ms | 118868 KB | Output is correct |
47 | Correct | 64 ms | 119376 KB | Output is correct |
48 | Correct | 64 ms | 119380 KB | Output is correct |
49 | Correct | 63 ms | 119376 KB | Output is correct |
50 | Correct | 61 ms | 118864 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 57 ms | 117600 KB | Output is correct |
2 | Correct | 52 ms | 117588 KB | Output is correct |
3 | Correct | 52 ms | 117588 KB | Output is correct |
4 | Correct | 54 ms | 117592 KB | Output is correct |
5 | Correct | 59 ms | 117804 KB | Output is correct |
6 | Correct | 54 ms | 117840 KB | Output is correct |
7 | Correct | 51 ms | 117772 KB | Output is correct |
8 | Correct | 60 ms | 117840 KB | Output is correct |
9 | Correct | 56 ms | 117904 KB | Output is correct |
10 | Correct | 55 ms | 117928 KB | Output is correct |
11 | Correct | 57 ms | 117872 KB | Output is correct |
12 | Correct | 58 ms | 117840 KB | Output is correct |
13 | Correct | 56 ms | 117732 KB | Output is correct |
14 | Correct | 65 ms | 117844 KB | Output is correct |
15 | Correct | 65 ms | 119380 KB | Output is correct |
16 | Correct | 66 ms | 118936 KB | Output is correct |
17 | Correct | 78 ms | 118868 KB | Output is correct |
18 | Correct | 74 ms | 118768 KB | Output is correct |
19 | Correct | 72 ms | 119548 KB | Output is correct |
20 | Correct | 360 ms | 141260 KB | Output is correct |
21 | Correct | 660 ms | 188804 KB | Output is correct |
22 | Correct | 643 ms | 188916 KB | Output is correct |
23 | Correct | 1018 ms | 166128 KB | Output is correct |
24 | Correct | 880 ms | 188912 KB | Output is correct |
25 | Correct | 586 ms | 161872 KB | Output is correct |
26 | Correct | 729 ms | 166896 KB | Output is correct |
27 | Correct | 1145 ms | 167152 KB | Output is correct |
28 | Correct | 656 ms | 187716 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 57 ms | 117728 KB | Output is correct |
2 | Correct | 58 ms | 117584 KB | Output is correct |
3 | Correct | 58 ms | 117836 KB | Output is correct |
4 | Correct | 58 ms | 117604 KB | Output is correct |
5 | Correct | 64 ms | 117624 KB | Output is correct |
6 | Correct | 58 ms | 117724 KB | Output is correct |
7 | Correct | 57 ms | 117716 KB | Output is correct |
8 | Correct | 57 ms | 117844 KB | Output is correct |
9 | Correct | 56 ms | 117804 KB | Output is correct |
10 | Correct | 60 ms | 117840 KB | Output is correct |
11 | Correct | 61 ms | 117844 KB | Output is correct |
12 | Correct | 76 ms | 119376 KB | Output is correct |
13 | Correct | 70 ms | 118928 KB | Output is correct |
14 | Correct | 68 ms | 118864 KB | Output is correct |
15 | Correct | 391 ms | 141300 KB | Output is correct |
16 | Correct | 1020 ms | 166132 KB | Output is correct |
17 | Correct | 658 ms | 188908 KB | Output is correct |
18 | Correct | 662 ms | 188820 KB | Output is correct |
19 | Correct | 835 ms | 188916 KB | Output is correct |
20 | Correct | 990 ms | 166156 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 62 ms | 117776 KB | Output is correct |
2 | Correct | 53 ms | 117588 KB | Output is correct |
3 | Correct | 57 ms | 117584 KB | Output is correct |
4 | Correct | 54 ms | 117584 KB | Output is correct |
5 | Correct | 56 ms | 117852 KB | Output is correct |
6 | Correct | 55 ms | 117588 KB | Output is correct |
7 | Correct | 66 ms | 117720 KB | Output is correct |
8 | Correct | 62 ms | 117676 KB | Output is correct |
9 | Correct | 55 ms | 117788 KB | Output is correct |
10 | Correct | 54 ms | 117840 KB | Output is correct |
11 | Correct | 57 ms | 117840 KB | Output is correct |
12 | Correct | 54 ms | 117588 KB | Output is correct |
13 | Correct | 54 ms | 117656 KB | Output is correct |
14 | Correct | 55 ms | 117840 KB | Output is correct |
15 | Correct | 52 ms | 117588 KB | Output is correct |
16 | Correct | 56 ms | 117588 KB | Output is correct |
17 | Correct | 56 ms | 117632 KB | Output is correct |
18 | Correct | 61 ms | 117588 KB | Output is correct |
19 | Correct | 55 ms | 117588 KB | Output is correct |
20 | Correct | 56 ms | 117588 KB | Output is correct |
21 | Correct | 58 ms | 117588 KB | Output is correct |
22 | Correct | 54 ms | 117704 KB | Output is correct |
23 | Correct | 62 ms | 117728 KB | Output is correct |
24 | Correct | 59 ms | 117752 KB | Output is correct |
25 | Correct | 53 ms | 117844 KB | Output is correct |
26 | Correct | 54 ms | 117840 KB | Output is correct |
27 | Correct | 53 ms | 117844 KB | Output is correct |
28 | Correct | 52 ms | 117840 KB | Output is correct |
29 | Correct | 54 ms | 117840 KB | Output is correct |
30 | Correct | 52 ms | 117844 KB | Output is correct |
31 | Correct | 53 ms | 117844 KB | Output is correct |
32 | Correct | 54 ms | 117816 KB | Output is correct |
33 | Correct | 53 ms | 117660 KB | Output is correct |
34 | Correct | 56 ms | 117788 KB | Output is correct |
35 | Correct | 55 ms | 117840 KB | Output is correct |
36 | Correct | 57 ms | 117848 KB | Output is correct |
37 | Correct | 53 ms | 117800 KB | Output is correct |
38 | Correct | 53 ms | 117852 KB | Output is correct |
39 | Correct | 63 ms | 119376 KB | Output is correct |
40 | Correct | 80 ms | 119432 KB | Output is correct |
41 | Correct | 69 ms | 119380 KB | Output is correct |
42 | Correct | 64 ms | 118868 KB | Output is correct |
43 | Correct | 60 ms | 118864 KB | Output is correct |
44 | Correct | 61 ms | 118784 KB | Output is correct |
45 | Correct | 63 ms | 118868 KB | Output is correct |
46 | Correct | 72 ms | 118868 KB | Output is correct |
47 | Correct | 64 ms | 119376 KB | Output is correct |
48 | Correct | 64 ms | 119380 KB | Output is correct |
49 | Correct | 63 ms | 119376 KB | Output is correct |
50 | Correct | 61 ms | 118864 KB | Output is correct |
51 | Correct | 57 ms | 117600 KB | Output is correct |
52 | Correct | 52 ms | 117588 KB | Output is correct |
53 | Correct | 52 ms | 117588 KB | Output is correct |
54 | Correct | 54 ms | 117592 KB | Output is correct |
55 | Correct | 59 ms | 117804 KB | Output is correct |
56 | Correct | 54 ms | 117840 KB | Output is correct |
57 | Correct | 51 ms | 117772 KB | Output is correct |
58 | Correct | 60 ms | 117840 KB | Output is correct |
59 | Correct | 56 ms | 117904 KB | Output is correct |
60 | Correct | 55 ms | 117928 KB | Output is correct |
61 | Correct | 57 ms | 117872 KB | Output is correct |
62 | Correct | 58 ms | 117840 KB | Output is correct |
63 | Correct | 56 ms | 117732 KB | Output is correct |
64 | Correct | 65 ms | 117844 KB | Output is correct |
65 | Correct | 65 ms | 119380 KB | Output is correct |
66 | Correct | 66 ms | 118936 KB | Output is correct |
67 | Correct | 78 ms | 118868 KB | Output is correct |
68 | Correct | 74 ms | 118768 KB | Output is correct |
69 | Correct | 72 ms | 119548 KB | Output is correct |
70 | Correct | 360 ms | 141260 KB | Output is correct |
71 | Correct | 660 ms | 188804 KB | Output is correct |
72 | Correct | 643 ms | 188916 KB | Output is correct |
73 | Correct | 1018 ms | 166128 KB | Output is correct |
74 | Correct | 880 ms | 188912 KB | Output is correct |
75 | Correct | 586 ms | 161872 KB | Output is correct |
76 | Correct | 729 ms | 166896 KB | Output is correct |
77 | Correct | 1145 ms | 167152 KB | Output is correct |
78 | Correct | 656 ms | 187716 KB | Output is correct |
79 | Correct | 57 ms | 117728 KB | Output is correct |
80 | Correct | 58 ms | 117584 KB | Output is correct |
81 | Correct | 58 ms | 117836 KB | Output is correct |
82 | Correct | 58 ms | 117604 KB | Output is correct |
83 | Correct | 64 ms | 117624 KB | Output is correct |
84 | Correct | 58 ms | 117724 KB | Output is correct |
85 | Correct | 57 ms | 117716 KB | Output is correct |
86 | Correct | 57 ms | 117844 KB | Output is correct |
87 | Correct | 56 ms | 117804 KB | Output is correct |
88 | Correct | 60 ms | 117840 KB | Output is correct |
89 | Correct | 61 ms | 117844 KB | Output is correct |
90 | Correct | 76 ms | 119376 KB | Output is correct |
91 | Correct | 70 ms | 118928 KB | Output is correct |
92 | Correct | 68 ms | 118864 KB | Output is correct |
93 | Correct | 391 ms | 141300 KB | Output is correct |
94 | Correct | 1020 ms | 166132 KB | Output is correct |
95 | Correct | 658 ms | 188908 KB | Output is correct |
96 | Correct | 662 ms | 188820 KB | Output is correct |
97 | Correct | 835 ms | 188916 KB | Output is correct |
98 | Correct | 990 ms | 166156 KB | Output is correct |
99 | Correct | 657 ms | 189240 KB | Output is correct |
100 | Correct | 642 ms | 188916 KB | Output is correct |
101 | Correct | 1085 ms | 189236 KB | Output is correct |
102 | Correct | 1054 ms | 189020 KB | Output is correct |
103 | Correct | 1038 ms | 167116 KB | Output is correct |
104 | Correct | 681 ms | 186692 KB | Output is correct |
105 | Correct | 796 ms | 187632 KB | Output is correct |