Submission #707574

# Submission time Handle Problem Language Result Execution time Memory
707574 2023-03-09T11:17:46 Z Trisanu_Das Osumnjičeni (COCI21_osumnjiceni) C++17
110 / 110
295 ms 31176 KB
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ar array
 
const int mxN=2e5;
int n, q, l[mxN], r[mxN], anc[mxN][18];
 
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for (int i=0; i<n; ++i)
		cin >> l[i] >> r[i];
	set<ar<int, 2>> s;
	for (int i=n-1, j=n-1; ~i; --i) {
		while(1) {
			if (s.empty()||r[i]<(*s.begin())[0]||l[i]>(*s.rbegin())[1]) {
				s.insert({l[i], r[i]});
				break;
			}
			auto it=s.lower_bound({l[i], -1});
			if ((it==s.end()||r[i]<(*it)[0])&&(it==s.begin()||(*prev(it))[1]<l[i])) {
				s.insert({l[i], r[i]});
				break;
			}
			s.erase({l[j], r[j]});
			--j;
		}
		anc[i][0]=j+1;
	}
	for (int j=1; j<18; ++j)
		for (int i=0; i<n; ++i)
			anc[i][j]=anc[i][j-1]==n?n:anc[anc[i][j-1]][j-1];
	cin >> q;
	while(q--) {
		int a, b;
		cin >> a >> b, --a, --b;
		int ans=0;
		for (int i=17; ~i; --i)
			if (anc[a][i]<=b) {
				ans+=1<<i;
				a=anc[a][i];
			}
		cout << ans+1 << "\n";
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 75 ms 15260 KB Output is correct
2 Correct 76 ms 15096 KB Output is correct
3 Correct 77 ms 15072 KB Output is correct
4 Correct 95 ms 15160 KB Output is correct
5 Correct 81 ms 15856 KB Output is correct
6 Correct 76 ms 18076 KB Output is correct
7 Correct 81 ms 18408 KB Output is correct
8 Correct 84 ms 18380 KB Output is correct
9 Correct 92 ms 18856 KB Output is correct
10 Correct 90 ms 18220 KB Output is correct
11 Correct 183 ms 28124 KB Output is correct
12 Correct 180 ms 26304 KB Output is correct
13 Correct 194 ms 26196 KB Output is correct
14 Correct 199 ms 24012 KB Output is correct
15 Correct 212 ms 22220 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 87 ms 19152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 724 KB Output is correct
2 Correct 4 ms 852 KB Output is correct
3 Correct 4 ms 856 KB Output is correct
4 Correct 4 ms 848 KB Output is correct
5 Correct 5 ms 852 KB Output is correct
6 Correct 4 ms 852 KB Output is correct
7 Correct 4 ms 848 KB Output is correct
8 Correct 4 ms 772 KB Output is correct
9 Correct 4 ms 852 KB Output is correct
10 Correct 3 ms 852 KB Output is correct
11 Correct 5 ms 980 KB Output is correct
12 Correct 4 ms 964 KB Output is correct
13 Correct 5 ms 980 KB Output is correct
14 Correct 5 ms 852 KB Output is correct
15 Correct 4 ms 848 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 3 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 724 KB Output is correct
2 Correct 4 ms 852 KB Output is correct
3 Correct 4 ms 856 KB Output is correct
4 Correct 4 ms 848 KB Output is correct
5 Correct 5 ms 852 KB Output is correct
6 Correct 4 ms 852 KB Output is correct
7 Correct 4 ms 848 KB Output is correct
8 Correct 4 ms 772 KB Output is correct
9 Correct 4 ms 852 KB Output is correct
10 Correct 3 ms 852 KB Output is correct
11 Correct 5 ms 980 KB Output is correct
12 Correct 4 ms 964 KB Output is correct
13 Correct 5 ms 980 KB Output is correct
14 Correct 5 ms 852 KB Output is correct
15 Correct 4 ms 848 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 3 ms 852 KB Output is correct
18 Correct 66 ms 3532 KB Output is correct
19 Correct 61 ms 3152 KB Output is correct
20 Correct 68 ms 3528 KB Output is correct
21 Correct 63 ms 3244 KB Output is correct
22 Correct 63 ms 3324 KB Output is correct
23 Correct 71 ms 3240 KB Output is correct
24 Correct 71 ms 3384 KB Output is correct
25 Correct 71 ms 3424 KB Output is correct
26 Correct 60 ms 3404 KB Output is correct
27 Correct 59 ms 3140 KB Output is correct
28 Correct 55 ms 3020 KB Output is correct
29 Correct 58 ms 3092 KB Output is correct
30 Correct 48 ms 3104 KB Output is correct
31 Correct 46 ms 2880 KB Output is correct
32 Correct 55 ms 3044 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 51 ms 3164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 15928 KB Output is correct
2 Correct 102 ms 19452 KB Output is correct
3 Correct 75 ms 18080 KB Output is correct
4 Correct 80 ms 17868 KB Output is correct
5 Correct 83 ms 18460 KB Output is correct
6 Correct 68 ms 18144 KB Output is correct
7 Correct 88 ms 17976 KB Output is correct
8 Correct 80 ms 18016 KB Output is correct
9 Correct 79 ms 17944 KB Output is correct
10 Correct 100 ms 19364 KB Output is correct
11 Correct 157 ms 26060 KB Output is correct
12 Correct 181 ms 28592 KB Output is correct
13 Correct 150 ms 26072 KB Output is correct
14 Correct 164 ms 22336 KB Output is correct
15 Correct 213 ms 24268 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 70 ms 18404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 15260 KB Output is correct
2 Correct 76 ms 15096 KB Output is correct
3 Correct 77 ms 15072 KB Output is correct
4 Correct 95 ms 15160 KB Output is correct
5 Correct 81 ms 15856 KB Output is correct
6 Correct 76 ms 18076 KB Output is correct
7 Correct 81 ms 18408 KB Output is correct
8 Correct 84 ms 18380 KB Output is correct
9 Correct 92 ms 18856 KB Output is correct
10 Correct 90 ms 18220 KB Output is correct
11 Correct 183 ms 28124 KB Output is correct
12 Correct 180 ms 26304 KB Output is correct
13 Correct 194 ms 26196 KB Output is correct
14 Correct 199 ms 24012 KB Output is correct
15 Correct 212 ms 22220 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 87 ms 19152 KB Output is correct
18 Correct 3 ms 724 KB Output is correct
19 Correct 4 ms 852 KB Output is correct
20 Correct 4 ms 856 KB Output is correct
21 Correct 4 ms 848 KB Output is correct
22 Correct 5 ms 852 KB Output is correct
23 Correct 4 ms 852 KB Output is correct
24 Correct 4 ms 848 KB Output is correct
25 Correct 4 ms 772 KB Output is correct
26 Correct 4 ms 852 KB Output is correct
27 Correct 3 ms 852 KB Output is correct
28 Correct 5 ms 980 KB Output is correct
29 Correct 4 ms 964 KB Output is correct
30 Correct 5 ms 980 KB Output is correct
31 Correct 5 ms 852 KB Output is correct
32 Correct 4 ms 848 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 3 ms 852 KB Output is correct
35 Correct 66 ms 3532 KB Output is correct
36 Correct 61 ms 3152 KB Output is correct
37 Correct 68 ms 3528 KB Output is correct
38 Correct 63 ms 3244 KB Output is correct
39 Correct 63 ms 3324 KB Output is correct
40 Correct 71 ms 3240 KB Output is correct
41 Correct 71 ms 3384 KB Output is correct
42 Correct 71 ms 3424 KB Output is correct
43 Correct 60 ms 3404 KB Output is correct
44 Correct 59 ms 3140 KB Output is correct
45 Correct 55 ms 3020 KB Output is correct
46 Correct 58 ms 3092 KB Output is correct
47 Correct 48 ms 3104 KB Output is correct
48 Correct 46 ms 2880 KB Output is correct
49 Correct 55 ms 3044 KB Output is correct
50 Correct 0 ms 340 KB Output is correct
51 Correct 51 ms 3164 KB Output is correct
52 Correct 82 ms 15928 KB Output is correct
53 Correct 102 ms 19452 KB Output is correct
54 Correct 75 ms 18080 KB Output is correct
55 Correct 80 ms 17868 KB Output is correct
56 Correct 83 ms 18460 KB Output is correct
57 Correct 68 ms 18144 KB Output is correct
58 Correct 88 ms 17976 KB Output is correct
59 Correct 80 ms 18016 KB Output is correct
60 Correct 79 ms 17944 KB Output is correct
61 Correct 100 ms 19364 KB Output is correct
62 Correct 157 ms 26060 KB Output is correct
63 Correct 181 ms 28592 KB Output is correct
64 Correct 150 ms 26072 KB Output is correct
65 Correct 164 ms 22336 KB Output is correct
66 Correct 213 ms 24268 KB Output is correct
67 Correct 1 ms 328 KB Output is correct
68 Correct 70 ms 18404 KB Output is correct
69 Correct 223 ms 21988 KB Output is correct
70 Correct 248 ms 22980 KB Output is correct
71 Correct 266 ms 21336 KB Output is correct
72 Correct 240 ms 22292 KB Output is correct
73 Correct 291 ms 22000 KB Output is correct
74 Correct 256 ms 23148 KB Output is correct
75 Correct 295 ms 21664 KB Output is correct
76 Correct 252 ms 23272 KB Output is correct
77 Correct 285 ms 21564 KB Output is correct
78 Correct 268 ms 22076 KB Output is correct
79 Correct 224 ms 31176 KB Output is correct
80 Correct 210 ms 28968 KB Output is correct
81 Correct 214 ms 28780 KB Output is correct
82 Correct 254 ms 25520 KB Output is correct
83 Correct 216 ms 24464 KB Output is correct
84 Correct 0 ms 212 KB Output is correct
85 Correct 141 ms 21736 KB Output is correct