답안 #852656

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
852656 2023-09-22T11:31:06 Z Trisanu_Das Event Hopping (BOI22_events) C++17
100 / 100
100 ms 13396 KB
#include <bits/stdc++.h>
using namespace std;
 
const int N = 1e5 + 10 , L = 18;
int n , q , l[N] , r[N] , mv[L][N];
vector <int> vec , st;
 
bool cmp(int a , int b) {
	if(r[a] != r[b]) return r[a] < r[b];
	return l[a] < l[b];
}
 
int Bs(int x){
	int low = -1 , high = st.size();
	while(high - low > 1) {
		int mid = (low + high) >> 1;
		if(r[st[mid]] >= x) high = mid;
		else low = mid;
	}
	return st[high];
}
 
int solve(int from , int to , int bit) {
	if(bit == -1) return 0;
	int nex = mv[bit][from];
	if(l[nex] > r[to]) return (1 << bit) + solve(nex , to , bit - 1);
	return solve(from , to , bit - 1);
}
 
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);  cout.tie(0);
	cin >> n >> q;
	for(int i = 1 ; i <= n ; i++) {
		cin >> l[i] >> r[i];
		vec.push_back(i);
	}
	sort(vec.begin() , vec.end() , cmp);
	for(int i = 1 ; i <= n ; i++) {
		int now = vec[i];
		while(!st.empty() && l[st.back()] >= l[now]) st.pop_back();
		st.push_back(now);
		mv[0][now] = Bs(l[now]);
	}
	for(int i = 1 ; i < L ; i++)   for(int j = 1 ; j <= n ; j++) mv[i][j] = mv[i - 1][mv[i - 1][j]];
	while(q--) {
		int s , e;  cin >> s >> e;
		if(l[mv[L - 1][e]] > r[s] || r[e] < r[s]) {
			cout << "impossible" << '\n';
			continue;
		}
		if(s == e) {
			cout << 0 << '\n';
			continue;
		}
		if(l[e] <= r[s]) {
			cout << 1 << '\n';
			continue;
		}
		cout << solve(e , s , L - 1) + 2 << '\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 69 ms 12940 KB Output is correct
3 Correct 70 ms 12888 KB Output is correct
4 Correct 73 ms 12768 KB Output is correct
5 Correct 71 ms 12756 KB Output is correct
6 Correct 68 ms 12884 KB Output is correct
7 Correct 67 ms 12884 KB Output is correct
8 Correct 59 ms 13396 KB Output is correct
9 Correct 67 ms 13320 KB Output is correct
10 Correct 67 ms 13140 KB Output is correct
11 Correct 62 ms 13264 KB Output is correct
12 Correct 42 ms 12496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 2 ms 6488 KB Output is correct
4 Correct 1 ms 6488 KB Output is correct
5 Correct 1 ms 6488 KB Output is correct
6 Correct 1 ms 6488 KB Output is correct
7 Correct 1 ms 6488 KB Output is correct
8 Correct 1 ms 6744 KB Output is correct
9 Correct 1 ms 6488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 2 ms 6488 KB Output is correct
4 Correct 1 ms 6488 KB Output is correct
5 Correct 1 ms 6488 KB Output is correct
6 Correct 1 ms 6488 KB Output is correct
7 Correct 1 ms 6488 KB Output is correct
8 Correct 1 ms 6744 KB Output is correct
9 Correct 1 ms 6488 KB Output is correct
10 Correct 1 ms 6488 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6488 KB Output is correct
13 Correct 1 ms 6488 KB Output is correct
14 Correct 1 ms 6488 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6488 KB Output is correct
17 Correct 1 ms 6488 KB Output is correct
18 Correct 1 ms 6488 KB Output is correct
19 Correct 36 ms 8020 KB Output is correct
20 Correct 23 ms 8280 KB Output is correct
21 Correct 34 ms 8528 KB Output is correct
22 Correct 20 ms 8500 KB Output is correct
23 Correct 23 ms 8272 KB Output is correct
24 Correct 19 ms 8280 KB Output is correct
25 Correct 27 ms 8024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6488 KB Output is correct
3 Correct 2 ms 6488 KB Output is correct
4 Correct 1 ms 6488 KB Output is correct
5 Correct 1 ms 6488 KB Output is correct
6 Correct 1 ms 6488 KB Output is correct
7 Correct 1 ms 6488 KB Output is correct
8 Correct 1 ms 6744 KB Output is correct
9 Correct 1 ms 6488 KB Output is correct
10 Correct 1 ms 6488 KB Output is correct
11 Correct 1 ms 6488 KB Output is correct
12 Correct 1 ms 6488 KB Output is correct
13 Correct 1 ms 6676 KB Output is correct
14 Correct 1 ms 6488 KB Output is correct
15 Correct 1 ms 6488 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6488 KB Output is correct
18 Correct 1 ms 6488 KB Output is correct
19 Correct 42 ms 11088 KB Output is correct
20 Correct 39 ms 10252 KB Output is correct
21 Correct 40 ms 10448 KB Output is correct
22 Correct 56 ms 11052 KB Output is correct
23 Correct 45 ms 10912 KB Output is correct
24 Correct 42 ms 11092 KB Output is correct
25 Correct 26 ms 9936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 12996 KB Output is correct
2 Correct 75 ms 12736 KB Output is correct
3 Correct 81 ms 12828 KB Output is correct
4 Correct 61 ms 13272 KB Output is correct
5 Correct 71 ms 13212 KB Output is correct
6 Correct 100 ms 12860 KB Output is correct
7 Correct 71 ms 13012 KB Output is correct
8 Correct 66 ms 13136 KB Output is correct
9 Correct 42 ms 10940 KB Output is correct
10 Correct 71 ms 12680 KB Output is correct
11 Correct 62 ms 12364 KB Output is correct
12 Correct 68 ms 12540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 69 ms 12940 KB Output is correct
3 Correct 70 ms 12888 KB Output is correct
4 Correct 73 ms 12768 KB Output is correct
5 Correct 71 ms 12756 KB Output is correct
6 Correct 68 ms 12884 KB Output is correct
7 Correct 67 ms 12884 KB Output is correct
8 Correct 59 ms 13396 KB Output is correct
9 Correct 67 ms 13320 KB Output is correct
10 Correct 67 ms 13140 KB Output is correct
11 Correct 62 ms 13264 KB Output is correct
12 Correct 42 ms 12496 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6488 KB Output is correct
15 Correct 2 ms 6488 KB Output is correct
16 Correct 1 ms 6488 KB Output is correct
17 Correct 1 ms 6488 KB Output is correct
18 Correct 1 ms 6488 KB Output is correct
19 Correct 1 ms 6488 KB Output is correct
20 Correct 1 ms 6744 KB Output is correct
21 Correct 1 ms 6488 KB Output is correct
22 Correct 1 ms 6488 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6488 KB Output is correct
25 Correct 1 ms 6488 KB Output is correct
26 Correct 1 ms 6488 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6488 KB Output is correct
29 Correct 1 ms 6488 KB Output is correct
30 Correct 1 ms 6488 KB Output is correct
31 Correct 36 ms 8020 KB Output is correct
32 Correct 23 ms 8280 KB Output is correct
33 Correct 34 ms 8528 KB Output is correct
34 Correct 20 ms 8500 KB Output is correct
35 Correct 23 ms 8272 KB Output is correct
36 Correct 19 ms 8280 KB Output is correct
37 Correct 27 ms 8024 KB Output is correct
38 Correct 1 ms 6488 KB Output is correct
39 Correct 1 ms 6488 KB Output is correct
40 Correct 1 ms 6488 KB Output is correct
41 Correct 1 ms 6676 KB Output is correct
42 Correct 1 ms 6488 KB Output is correct
43 Correct 1 ms 6488 KB Output is correct
44 Correct 1 ms 6492 KB Output is correct
45 Correct 1 ms 6488 KB Output is correct
46 Correct 1 ms 6488 KB Output is correct
47 Correct 42 ms 11088 KB Output is correct
48 Correct 39 ms 10252 KB Output is correct
49 Correct 40 ms 10448 KB Output is correct
50 Correct 56 ms 11052 KB Output is correct
51 Correct 45 ms 10912 KB Output is correct
52 Correct 42 ms 11092 KB Output is correct
53 Correct 26 ms 9936 KB Output is correct
54 Correct 73 ms 12996 KB Output is correct
55 Correct 75 ms 12736 KB Output is correct
56 Correct 81 ms 12828 KB Output is correct
57 Correct 61 ms 13272 KB Output is correct
58 Correct 71 ms 13212 KB Output is correct
59 Correct 100 ms 12860 KB Output is correct
60 Correct 71 ms 13012 KB Output is correct
61 Correct 66 ms 13136 KB Output is correct
62 Correct 42 ms 10940 KB Output is correct
63 Correct 71 ms 12680 KB Output is correct
64 Correct 62 ms 12364 KB Output is correct
65 Correct 68 ms 12540 KB Output is correct
66 Correct 1 ms 6628 KB Output is correct
67 Correct 67 ms 12868 KB Output is correct
68 Correct 68 ms 12812 KB Output is correct
69 Correct 78 ms 12880 KB Output is correct
70 Correct 75 ms 12816 KB Output is correct
71 Correct 68 ms 12884 KB Output is correct
72 Correct 73 ms 12888 KB Output is correct
73 Correct 71 ms 13292 KB Output is correct
74 Correct 57 ms 13208 KB Output is correct
75 Correct 79 ms 13140 KB Output is correct
76 Correct 95 ms 13264 KB Output is correct
77 Correct 47 ms 12568 KB Output is correct
78 Correct 1 ms 6488 KB Output is correct
79 Correct 2 ms 6744 KB Output is correct
80 Correct 2 ms 6612 KB Output is correct
81 Correct 1 ms 6492 KB Output is correct
82 Correct 2 ms 6480 KB Output is correct
83 Correct 2 ms 6488 KB Output is correct
84 Correct 2 ms 6624 KB Output is correct
85 Correct 1 ms 6488 KB Output is correct
86 Correct 27 ms 8024 KB Output is correct
87 Correct 26 ms 8272 KB Output is correct
88 Correct 28 ms 8528 KB Output is correct
89 Correct 20 ms 8536 KB Output is correct
90 Correct 20 ms 8280 KB Output is correct
91 Correct 20 ms 8280 KB Output is correct
92 Correct 23 ms 8016 KB Output is correct
93 Correct 44 ms 11036 KB Output is correct
94 Correct 38 ms 10292 KB Output is correct
95 Correct 35 ms 10536 KB Output is correct
96 Correct 39 ms 10960 KB Output is correct
97 Correct 37 ms 11092 KB Output is correct
98 Correct 40 ms 11092 KB Output is correct
99 Correct 18 ms 9948 KB Output is correct
100 Correct 71 ms 12884 KB Output is correct
101 Correct 73 ms 12992 KB Output is correct
102 Correct 65 ms 13140 KB Output is correct
103 Correct 70 ms 12628 KB Output is correct
104 Correct 61 ms 12372 KB Output is correct
105 Correct 68 ms 12628 KB Output is correct
106 Correct 69 ms 12192 KB Output is correct
107 Correct 73 ms 12184 KB Output is correct
108 Correct 52 ms 12584 KB Output is correct
109 Correct 53 ms 12496 KB Output is correct
110 Correct 63 ms 12492 KB Output is correct
111 Correct 50 ms 12496 KB Output is correct