Submission #580899

# Submission time Handle Problem Language Result Execution time Memory
580899 2022-06-22T05:41:32 Z amunduzbaev Event Hopping (BOI22_events) C++17
100 / 100
208 ms 12248 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ar array
typedef int64_t ll;
//~ #define int ll

const int N = 1e5 + 5;
int l[N], r[N], p[N][20];

struct ST{
	int tree[N << 2];
	
	void sett(int i, int v, int lx = 0, int rx = N, int x = 1){
		if(lx == rx){
			if(r[v] > r[tree[x]]) tree[x] = v;
			return;
		}
		int m = (lx + rx) >> 1;
		if(i <= m) sett(i, v, lx, m, x << 1);
		else sett(i, v, m + 1, rx, x << 1 | 1);
		if(r[tree[x << 1]] > r[tree[x << 1 | 1]]) tree[x] = tree[x << 1];
		else tree[x] = tree[x << 1 | 1];
	}
	
	int get(int l, int r, int lx = 0, int rx = N, int x = 1){
		if(lx > r || rx < l) return 0;
		if(lx >= l && rx <= r) return tree[x];
		int m = (lx + rx) >> 1;
		int L = get(l, r, lx, m, x << 1);
		int R = get(l, r, m + 1, rx, x << 1 | 1);
		//~ cout<<::r[R]<<" "<<::r[L]<<" tree\n";
		if(::r[R] > ::r[L]) return R;
		else return L;
	}
}tree;

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n, q; cin>>n>>q;
	vector<int> t;
	//~ cout<<"->\n";
	for(int i=1;i<=n;i++){
		cin>>l[i]>>r[i];
		l[i] = 1e9 - l[i] + 1;
		r[i] = 1e9 - r[i] + 1;
		swap(l[i], r[i]);
		//~ cout<<l[i]<<" "<<r[i]<<"\n";
		t.push_back(l[i]);
	}
	
	sort(t.begin(), t.end());
	
	for(int i=1;i<=n;i++){
		int j = lower_bound(t.begin(), t.end(), l[i]) - t.begin();
		tree.sett(j, i);
		//~ cout<<j<<" ";
	} // cout<<"\n";
	
	for(int i=1;i<=n;i++){
		int l = lower_bound(t.begin(), t.end(), ::l[i]) - t.begin();
		int r = upper_bound(t.begin(), t.end(), ::r[i]) - t.begin() - 1;
		p[i][0] = tree.get(l, r);
		//~ cout<<l<<" "<<r<<" "<<p[i][0]<<"\n";
	}
	
	for(int j=1;j<20;j++){
		for(int i=1;i<=n;i++){
			p[i][j] = p[p[i][j-1]][j-1];
		}
	}
	
	for(int i=0;i<q;i++){
		int a, b; cin>>b>>a;
		if(l[b] < l[a]) { cout<<"impossible\n"; continue; }
		if(a == b) { cout<<0<<"\n"; continue; }
		int res = 0;
		for(int j=19;~j;j--){
			if(r[p[a][j]] < l[b]){
				a = p[a][j];
				res += (1 << j);
			}
		}
		if(l[b] <= r[a]){
			cout<<1<<"\n";
		} else if(l[b] <= r[p[a][0]]){
			cout<<res + 2<<"\n";
		} else {
			cout<<"impossible\n";
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 140 ms 11204 KB Output is correct
3 Correct 166 ms 11652 KB Output is correct
4 Correct 178 ms 11528 KB Output is correct
5 Correct 155 ms 11504 KB Output is correct
6 Correct 162 ms 11628 KB Output is correct
7 Correct 151 ms 11500 KB Output is correct
8 Correct 141 ms 12124 KB Output is correct
9 Correct 156 ms 12248 KB Output is correct
10 Correct 155 ms 11980 KB Output is correct
11 Correct 190 ms 11968 KB Output is correct
12 Correct 85 ms 11788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 36 ms 1740 KB Output is correct
20 Correct 45 ms 1404 KB Output is correct
21 Correct 37 ms 1700 KB Output is correct
22 Correct 34 ms 1804 KB Output is correct
23 Correct 27 ms 1652 KB Output is correct
24 Correct 35 ms 1716 KB Output is correct
25 Correct 32 ms 1228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 2 ms 476 KB Output is correct
16 Correct 1 ms 428 KB Output is correct
17 Correct 1 ms 480 KB Output is correct
18 Correct 1 ms 356 KB Output is correct
19 Correct 135 ms 10852 KB Output is correct
20 Correct 105 ms 10904 KB Output is correct
21 Correct 121 ms 10832 KB Output is correct
22 Correct 111 ms 10632 KB Output is correct
23 Correct 117 ms 11080 KB Output is correct
24 Correct 116 ms 10924 KB Output is correct
25 Correct 45 ms 9804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 149 ms 11320 KB Output is correct
2 Correct 164 ms 11340 KB Output is correct
3 Correct 185 ms 11272 KB Output is correct
4 Correct 153 ms 11636 KB Output is correct
5 Correct 155 ms 11524 KB Output is correct
6 Correct 175 ms 11416 KB Output is correct
7 Correct 190 ms 11460 KB Output is correct
8 Correct 163 ms 11520 KB Output is correct
9 Correct 115 ms 10720 KB Output is correct
10 Correct 178 ms 11360 KB Output is correct
11 Correct 148 ms 11172 KB Output is correct
12 Correct 162 ms 11060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 140 ms 11204 KB Output is correct
3 Correct 166 ms 11652 KB Output is correct
4 Correct 178 ms 11528 KB Output is correct
5 Correct 155 ms 11504 KB Output is correct
6 Correct 162 ms 11628 KB Output is correct
7 Correct 151 ms 11500 KB Output is correct
8 Correct 141 ms 12124 KB Output is correct
9 Correct 156 ms 12248 KB Output is correct
10 Correct 155 ms 11980 KB Output is correct
11 Correct 190 ms 11968 KB Output is correct
12 Correct 85 ms 11788 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 36 ms 1740 KB Output is correct
32 Correct 45 ms 1404 KB Output is correct
33 Correct 37 ms 1700 KB Output is correct
34 Correct 34 ms 1804 KB Output is correct
35 Correct 27 ms 1652 KB Output is correct
36 Correct 35 ms 1716 KB Output is correct
37 Correct 32 ms 1228 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 2 ms 476 KB Output is correct
44 Correct 1 ms 428 KB Output is correct
45 Correct 1 ms 480 KB Output is correct
46 Correct 1 ms 356 KB Output is correct
47 Correct 135 ms 10852 KB Output is correct
48 Correct 105 ms 10904 KB Output is correct
49 Correct 121 ms 10832 KB Output is correct
50 Correct 111 ms 10632 KB Output is correct
51 Correct 117 ms 11080 KB Output is correct
52 Correct 116 ms 10924 KB Output is correct
53 Correct 45 ms 9804 KB Output is correct
54 Correct 149 ms 11320 KB Output is correct
55 Correct 164 ms 11340 KB Output is correct
56 Correct 185 ms 11272 KB Output is correct
57 Correct 153 ms 11636 KB Output is correct
58 Correct 155 ms 11524 KB Output is correct
59 Correct 175 ms 11416 KB Output is correct
60 Correct 190 ms 11460 KB Output is correct
61 Correct 163 ms 11520 KB Output is correct
62 Correct 115 ms 10720 KB Output is correct
63 Correct 178 ms 11360 KB Output is correct
64 Correct 148 ms 11172 KB Output is correct
65 Correct 162 ms 11060 KB Output is correct
66 Correct 0 ms 340 KB Output is correct
67 Correct 152 ms 11320 KB Output is correct
68 Correct 154 ms 11612 KB Output is correct
69 Correct 199 ms 11344 KB Output is correct
70 Correct 161 ms 11560 KB Output is correct
71 Correct 161 ms 11484 KB Output is correct
72 Correct 182 ms 11596 KB Output is correct
73 Correct 136 ms 12004 KB Output is correct
74 Correct 152 ms 11956 KB Output is correct
75 Correct 164 ms 11824 KB Output is correct
76 Correct 151 ms 11728 KB Output is correct
77 Correct 111 ms 11672 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 1 ms 468 KB Output is correct
80 Correct 1 ms 468 KB Output is correct
81 Correct 1 ms 468 KB Output is correct
82 Correct 1 ms 468 KB Output is correct
83 Correct 2 ms 468 KB Output is correct
84 Correct 1 ms 468 KB Output is correct
85 Correct 1 ms 468 KB Output is correct
86 Correct 35 ms 1412 KB Output is correct
87 Correct 48 ms 1448 KB Output is correct
88 Correct 39 ms 1680 KB Output is correct
89 Correct 26 ms 1852 KB Output is correct
90 Correct 32 ms 1708 KB Output is correct
91 Correct 27 ms 1708 KB Output is correct
92 Correct 40 ms 1268 KB Output is correct
93 Correct 117 ms 10512 KB Output is correct
94 Correct 105 ms 10568 KB Output is correct
95 Correct 118 ms 10668 KB Output is correct
96 Correct 126 ms 10552 KB Output is correct
97 Correct 102 ms 10856 KB Output is correct
98 Correct 124 ms 10672 KB Output is correct
99 Correct 48 ms 9644 KB Output is correct
100 Correct 208 ms 11468 KB Output is correct
101 Correct 166 ms 11640 KB Output is correct
102 Correct 150 ms 11856 KB Output is correct
103 Correct 163 ms 11380 KB Output is correct
104 Correct 147 ms 11112 KB Output is correct
105 Correct 178 ms 11368 KB Output is correct
106 Correct 160 ms 11500 KB Output is correct
107 Correct 186 ms 11736 KB Output is correct
108 Correct 162 ms 11820 KB Output is correct
109 Correct 166 ms 11752 KB Output is correct
110 Correct 164 ms 11680 KB Output is correct
111 Correct 170 ms 11448 KB Output is correct