# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
895498 | 2023-12-30T05:50:43 Z | 1bin | Event Hopping (BOI22_events) | C++14 | 99 ms | 20132 KB |
#include <bits/stdc++.h> using namespace std; #define all(v) v.begin(), v.end() typedef long long ll; const int b = 1 << 18; int n, q, p[b][18], s[b], e[b], l, r; pair<int, int> seg[b * 2]; vector<int> tmp; void upd(int ix, pair<int, int> v){ ix += b; while(ix){ seg[ix] = min(seg[ix], v); ix /= 2; } return; } int qry(int l, int r){ l += b; r += b; pair<int, int> ret = {2e9, -1}; while(l <= r){ if(l & 1) ret = min(ret, seg[l++]); if(!(r & 1)) ret = min(ret, seg[r--]); l /= 2; r /= 2; } return ret.second; } int main(void){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> q; for(int i = 1; i <= n; i++){ cin >> s[i] >> e[i]; tmp.emplace_back(s[i]); tmp.emplace_back(e[i]); } sort(all(tmp)); tmp.erase(unique(all(tmp)), tmp.end()); memset(seg, 0x3f, sizeof(seg)); for(int i = 1; i <= n; i++) { s[i] = lower_bound(all(tmp), s[i]) - tmp.begin(); e[i] = lower_bound(all(tmp), e[i]) - tmp.begin(); upd(e[i], {s[i], i}); } for(int i = 1; i <= n; i++) p[i][0] = qry(s[i], e[i]); for(int j = 1; j < 17; j++) for(int i = 1; i <= n; i++) p[i][j] = p[p[i][j - 1]][j - 1]; while(q--){ cin >> l >> r; if(l == r) cout << "0\n"; else if(e[r] < e[l]) cout << "impossible\n"; else if(e[l] >= s[r]) cout << "1\n"; else{ int ans = 0; for(int i = 16; i >= 0; i--) if(e[l] < s[p[r][i]]) r = p[r][i], ans += 1 << i; if(s[p[r][0]] <= e[l]) cout << ans + 2 << '\n'; else cout << "impossible\n"; } } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 6748 KB | Output is correct |
2 | Correct | 77 ms | 19408 KB | Output is correct |
3 | Correct | 83 ms | 19604 KB | Output is correct |
4 | Correct | 88 ms | 19548 KB | Output is correct |
5 | Correct | 84 ms | 19596 KB | Output is correct |
6 | Correct | 91 ms | 19844 KB | Output is correct |
7 | Correct | 84 ms | 19664 KB | Output is correct |
8 | Correct | 77 ms | 19948 KB | Output is correct |
9 | Correct | 79 ms | 19940 KB | Output is correct |
10 | Correct | 87 ms | 20132 KB | Output is correct |
11 | Correct | 81 ms | 19916 KB | Output is correct |
12 | Correct | 51 ms | 19348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 6748 KB | Output is correct |
2 | Correct | 2 ms | 6748 KB | Output is correct |
3 | Correct | 2 ms | 6748 KB | Output is correct |
4 | Correct | 1 ms | 6748 KB | Output is correct |
5 | Correct | 2 ms | 6748 KB | Output is correct |
6 | Correct | 1 ms | 6748 KB | Output is correct |
7 | Correct | 2 ms | 6748 KB | Output is correct |
8 | Correct | 2 ms | 6748 KB | Output is correct |
9 | Correct | 1 ms | 6748 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 6748 KB | Output is correct |
2 | Correct | 2 ms | 6748 KB | Output is correct |
3 | Correct | 2 ms | 6748 KB | Output is correct |
4 | Correct | 1 ms | 6748 KB | Output is correct |
5 | Correct | 2 ms | 6748 KB | Output is correct |
6 | Correct | 1 ms | 6748 KB | Output is correct |
7 | Correct | 2 ms | 6748 KB | Output is correct |
8 | Correct | 2 ms | 6748 KB | Output is correct |
9 | Correct | 1 ms | 6748 KB | Output is correct |
10 | Correct | 1 ms | 6944 KB | Output is correct |
11 | Correct | 1 ms | 6748 KB | Output is correct |
12 | Correct | 1 ms | 6748 KB | Output is correct |
13 | Correct | 2 ms | 6748 KB | Output is correct |
14 | Correct | 1 ms | 6748 KB | Output is correct |
15 | Correct | 1 ms | 6748 KB | Output is correct |
16 | Correct | 2 ms | 6748 KB | Output is correct |
17 | Correct | 2 ms | 6748 KB | Output is correct |
18 | Correct | 1 ms | 6748 KB | Output is correct |
19 | Correct | 26 ms | 10196 KB | Output is correct |
20 | Correct | 23 ms | 10332 KB | Output is correct |
21 | Correct | 32 ms | 10672 KB | Output is correct |
22 | Correct | 20 ms | 10576 KB | Output is correct |
23 | Correct | 24 ms | 10588 KB | Output is correct |
24 | Correct | 17 ms | 10576 KB | Output is correct |
25 | Correct | 22 ms | 10108 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 6748 KB | Output is correct |
2 | Correct | 2 ms | 6748 KB | Output is correct |
3 | Correct | 2 ms | 6748 KB | Output is correct |
4 | Correct | 1 ms | 6748 KB | Output is correct |
5 | Correct | 2 ms | 6748 KB | Output is correct |
6 | Correct | 1 ms | 6748 KB | Output is correct |
7 | Correct | 2 ms | 6748 KB | Output is correct |
8 | Correct | 2 ms | 6748 KB | Output is correct |
9 | Correct | 1 ms | 6748 KB | Output is correct |
10 | Correct | 1 ms | 6748 KB | Output is correct |
11 | Correct | 1 ms | 6748 KB | Output is correct |
12 | Correct | 2 ms | 6624 KB | Output is correct |
13 | Correct | 2 ms | 6748 KB | Output is correct |
14 | Correct | 1 ms | 6748 KB | Output is correct |
15 | Correct | 2 ms | 6748 KB | Output is correct |
16 | Correct | 2 ms | 6748 KB | Output is correct |
17 | Correct | 1 ms | 6748 KB | Output is correct |
18 | Correct | 1 ms | 6748 KB | Output is correct |
19 | Correct | 60 ms | 17632 KB | Output is correct |
20 | Correct | 55 ms | 17052 KB | Output is correct |
21 | Correct | 64 ms | 17612 KB | Output is correct |
22 | Correct | 61 ms | 18180 KB | Output is correct |
23 | Correct | 72 ms | 17612 KB | Output is correct |
24 | Correct | 67 ms | 17616 KB | Output is correct |
25 | Correct | 23 ms | 17100 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 77 ms | 19588 KB | Output is correct |
2 | Correct | 81 ms | 19584 KB | Output is correct |
3 | Correct | 87 ms | 19592 KB | Output is correct |
4 | Correct | 78 ms | 19988 KB | Output is correct |
5 | Correct | 82 ms | 19916 KB | Output is correct |
6 | Correct | 89 ms | 19672 KB | Output is correct |
7 | Correct | 90 ms | 19592 KB | Output is correct |
8 | Correct | 90 ms | 19656 KB | Output is correct |
9 | Correct | 72 ms | 17684 KB | Output is correct |
10 | Correct | 89 ms | 19336 KB | Output is correct |
11 | Correct | 93 ms | 19076 KB | Output is correct |
12 | Correct | 88 ms | 19340 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 6748 KB | Output is correct |
2 | Correct | 77 ms | 19408 KB | Output is correct |
3 | Correct | 83 ms | 19604 KB | Output is correct |
4 | Correct | 88 ms | 19548 KB | Output is correct |
5 | Correct | 84 ms | 19596 KB | Output is correct |
6 | Correct | 91 ms | 19844 KB | Output is correct |
7 | Correct | 84 ms | 19664 KB | Output is correct |
8 | Correct | 77 ms | 19948 KB | Output is correct |
9 | Correct | 79 ms | 19940 KB | Output is correct |
10 | Correct | 87 ms | 20132 KB | Output is correct |
11 | Correct | 81 ms | 19916 KB | Output is correct |
12 | Correct | 51 ms | 19348 KB | Output is correct |
13 | Correct | 1 ms | 6748 KB | Output is correct |
14 | Correct | 2 ms | 6748 KB | Output is correct |
15 | Correct | 2 ms | 6748 KB | Output is correct |
16 | Correct | 1 ms | 6748 KB | Output is correct |
17 | Correct | 2 ms | 6748 KB | Output is correct |
18 | Correct | 1 ms | 6748 KB | Output is correct |
19 | Correct | 2 ms | 6748 KB | Output is correct |
20 | Correct | 2 ms | 6748 KB | Output is correct |
21 | Correct | 1 ms | 6748 KB | Output is correct |
22 | Correct | 1 ms | 6944 KB | Output is correct |
23 | Correct | 1 ms | 6748 KB | Output is correct |
24 | Correct | 1 ms | 6748 KB | Output is correct |
25 | Correct | 2 ms | 6748 KB | Output is correct |
26 | Correct | 1 ms | 6748 KB | Output is correct |
27 | Correct | 1 ms | 6748 KB | Output is correct |
28 | Correct | 2 ms | 6748 KB | Output is correct |
29 | Correct | 2 ms | 6748 KB | Output is correct |
30 | Correct | 1 ms | 6748 KB | Output is correct |
31 | Correct | 26 ms | 10196 KB | Output is correct |
32 | Correct | 23 ms | 10332 KB | Output is correct |
33 | Correct | 32 ms | 10672 KB | Output is correct |
34 | Correct | 20 ms | 10576 KB | Output is correct |
35 | Correct | 24 ms | 10588 KB | Output is correct |
36 | Correct | 17 ms | 10576 KB | Output is correct |
37 | Correct | 22 ms | 10108 KB | Output is correct |
38 | Correct | 1 ms | 6748 KB | Output is correct |
39 | Correct | 1 ms | 6748 KB | Output is correct |
40 | Correct | 2 ms | 6624 KB | Output is correct |
41 | Correct | 2 ms | 6748 KB | Output is correct |
42 | Correct | 1 ms | 6748 KB | Output is correct |
43 | Correct | 2 ms | 6748 KB | Output is correct |
44 | Correct | 2 ms | 6748 KB | Output is correct |
45 | Correct | 1 ms | 6748 KB | Output is correct |
46 | Correct | 1 ms | 6748 KB | Output is correct |
47 | Correct | 60 ms | 17632 KB | Output is correct |
48 | Correct | 55 ms | 17052 KB | Output is correct |
49 | Correct | 64 ms | 17612 KB | Output is correct |
50 | Correct | 61 ms | 18180 KB | Output is correct |
51 | Correct | 72 ms | 17612 KB | Output is correct |
52 | Correct | 67 ms | 17616 KB | Output is correct |
53 | Correct | 23 ms | 17100 KB | Output is correct |
54 | Correct | 77 ms | 19588 KB | Output is correct |
55 | Correct | 81 ms | 19584 KB | Output is correct |
56 | Correct | 87 ms | 19592 KB | Output is correct |
57 | Correct | 78 ms | 19988 KB | Output is correct |
58 | Correct | 82 ms | 19916 KB | Output is correct |
59 | Correct | 89 ms | 19672 KB | Output is correct |
60 | Correct | 90 ms | 19592 KB | Output is correct |
61 | Correct | 90 ms | 19656 KB | Output is correct |
62 | Correct | 72 ms | 17684 KB | Output is correct |
63 | Correct | 89 ms | 19336 KB | Output is correct |
64 | Correct | 93 ms | 19076 KB | Output is correct |
65 | Correct | 88 ms | 19340 KB | Output is correct |
66 | Correct | 1 ms | 6748 KB | Output is correct |
67 | Correct | 78 ms | 19504 KB | Output is correct |
68 | Correct | 80 ms | 19460 KB | Output is correct |
69 | Correct | 87 ms | 19400 KB | Output is correct |
70 | Correct | 84 ms | 19660 KB | Output is correct |
71 | Correct | 86 ms | 19656 KB | Output is correct |
72 | Correct | 83 ms | 19660 KB | Output is correct |
73 | Correct | 79 ms | 19916 KB | Output is correct |
74 | Correct | 78 ms | 20104 KB | Output is correct |
75 | Correct | 84 ms | 19940 KB | Output is correct |
76 | Correct | 81 ms | 19920 KB | Output is correct |
77 | Correct | 51 ms | 19152 KB | Output is correct |
78 | Correct | 1 ms | 6748 KB | Output is correct |
79 | Correct | 1 ms | 6748 KB | Output is correct |
80 | Correct | 2 ms | 6748 KB | Output is correct |
81 | Correct | 1 ms | 6748 KB | Output is correct |
82 | Correct | 1 ms | 6748 KB | Output is correct |
83 | Correct | 2 ms | 6748 KB | Output is correct |
84 | Correct | 2 ms | 6616 KB | Output is correct |
85 | Correct | 1 ms | 6900 KB | Output is correct |
86 | Correct | 26 ms | 10304 KB | Output is correct |
87 | Correct | 23 ms | 10588 KB | Output is correct |
88 | Correct | 26 ms | 10576 KB | Output is correct |
89 | Correct | 20 ms | 10576 KB | Output is correct |
90 | Correct | 19 ms | 10588 KB | Output is correct |
91 | Correct | 18 ms | 10588 KB | Output is correct |
92 | Correct | 22 ms | 10072 KB | Output is correct |
93 | Correct | 57 ms | 17616 KB | Output is correct |
94 | Correct | 55 ms | 17060 KB | Output is correct |
95 | Correct | 65 ms | 17612 KB | Output is correct |
96 | Correct | 59 ms | 17616 KB | Output is correct |
97 | Correct | 72 ms | 17612 KB | Output is correct |
98 | Correct | 66 ms | 17612 KB | Output is correct |
99 | Correct | 23 ms | 17076 KB | Output is correct |
100 | Correct | 89 ms | 19664 KB | Output is correct |
101 | Correct | 93 ms | 19664 KB | Output is correct |
102 | Correct | 89 ms | 19884 KB | Output is correct |
103 | Correct | 88 ms | 19316 KB | Output is correct |
104 | Correct | 91 ms | 19080 KB | Output is correct |
105 | Correct | 87 ms | 19172 KB | Output is correct |
106 | Correct | 79 ms | 18892 KB | Output is correct |
107 | Correct | 84 ms | 18832 KB | Output is correct |
108 | Correct | 84 ms | 19652 KB | Output is correct |
109 | Correct | 86 ms | 19664 KB | Output is correct |
110 | Correct | 97 ms | 19588 KB | Output is correct |
111 | Correct | 99 ms | 19644 KB | Output is correct |