답안 #855892

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
855892 2023-10-02T07:06:20 Z NotLinux Osumnjičeni (COCI21_osumnjiceni) C++17
110 / 110
420 ms 33668 KB
#include <bits/stdc++.h>
using namespace std;
void solve(){
	int n;cin >> n;
	int l[n],r[n],lift[n+1][21];
	lift[n][0] = n;
	for(int i = 0;i<n;i++)cin >> l[i] >> r[i];
	set < pair < int , int > > ste;
	int rp = 0;
	for(int lp = 0;lp < n;lp++){
		while(rp != n){
			//cout << lp << " : ";for(auto itr : ste)cout << itr.first << "," << itr.second << "   ";cout << endl;
			if(ste.size() == 0){
			//	cout << "added " << lp << " " << rp << endl;
				ste.insert({l[rp],r[rp]});
				rp++;
			}
			else{
				auto it = ste.lower_bound(make_pair(l[rp],1e9 + 7));
				pair < int , int > cand1 , cand2;

				if(it == ste.end())cand2 = {-1,-1};
				else cand2 = *it;

				if(it == ste.begin())cand1 = {-1,-1};
				else cand1 = *(--it);

			//	cout << "trying : " << lp << " " << rp << " " << cand1.first << " " << cand1.second << " : " << cand2.first << " " << cand2.second << endl;
				if((cand1.first > r[rp] or cand1.second < l[rp]) and (cand2.first > r[rp] or cand2.second < l[rp])){
					ste.insert({l[rp],r[rp]});
					rp++;
					//cout << "succes" << endl;
				}
				else {
					//cout << "failure" << endl;
					break;
				}
			}
		}
		lift[lp][0] = rp;
		ste.extract({l[lp],r[lp]});
		//cout << lp << " " << rp << endl;
	}
	for(int i = 1;i<21;i++){
		for(int j = 0;j<=n;j++){
			lift[j][i] = lift[lift[j][i-1]][i-1];
		}
	}
	int q;cin >> q;
	while(q--){
		int ql,qr;cin >> ql >> qr;ql--;qr--;
		int ans = 0 , cur = ql;
		for(int i = 20;i>=0;i--){
			if(lift[cur][i] <= qr){
				cur = lift[cur][i];
				ans += (1 << i);
			}
		}
		cout << ans+1 << endl;
	}
}
signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int testcase = 1;//cin >> testcase;
	while(testcase--)solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 17496 KB Output is correct
2 Correct 63 ms 20816 KB Output is correct
3 Correct 61 ms 21076 KB Output is correct
4 Correct 65 ms 21336 KB Output is correct
5 Correct 67 ms 22088 KB Output is correct
6 Correct 56 ms 20056 KB Output is correct
7 Correct 60 ms 20560 KB Output is correct
8 Correct 62 ms 20560 KB Output is correct
9 Correct 71 ms 21328 KB Output is correct
10 Correct 67 ms 20484 KB Output is correct
11 Correct 168 ms 30384 KB Output is correct
12 Correct 165 ms 28756 KB Output is correct
13 Correct 152 ms 28296 KB Output is correct
14 Correct 152 ms 26448 KB Output is correct
15 Correct 144 ms 24448 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 59 ms 21536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 856 KB Output is correct
2 Correct 8 ms 984 KB Output is correct
3 Correct 12 ms 860 KB Output is correct
4 Correct 8 ms 860 KB Output is correct
5 Correct 8 ms 856 KB Output is correct
6 Correct 9 ms 856 KB Output is correct
7 Correct 8 ms 860 KB Output is correct
8 Correct 8 ms 980 KB Output is correct
9 Correct 9 ms 1008 KB Output is correct
10 Correct 8 ms 860 KB Output is correct
11 Correct 9 ms 1116 KB Output is correct
12 Correct 9 ms 1116 KB Output is correct
13 Correct 8 ms 1116 KB Output is correct
14 Correct 9 ms 856 KB Output is correct
15 Correct 9 ms 860 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 8 ms 1020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 856 KB Output is correct
2 Correct 8 ms 984 KB Output is correct
3 Correct 12 ms 860 KB Output is correct
4 Correct 8 ms 860 KB Output is correct
5 Correct 8 ms 856 KB Output is correct
6 Correct 9 ms 856 KB Output is correct
7 Correct 8 ms 860 KB Output is correct
8 Correct 8 ms 980 KB Output is correct
9 Correct 9 ms 1008 KB Output is correct
10 Correct 8 ms 860 KB Output is correct
11 Correct 9 ms 1116 KB Output is correct
12 Correct 9 ms 1116 KB Output is correct
13 Correct 8 ms 1116 KB Output is correct
14 Correct 9 ms 856 KB Output is correct
15 Correct 9 ms 860 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 8 ms 1020 KB Output is correct
18 Correct 284 ms 3516 KB Output is correct
19 Correct 243 ms 3412 KB Output is correct
20 Correct 274 ms 3632 KB Output is correct
21 Correct 243 ms 3696 KB Output is correct
22 Correct 257 ms 3408 KB Output is correct
23 Correct 246 ms 3448 KB Output is correct
24 Correct 254 ms 3512 KB Output is correct
25 Correct 274 ms 3452 KB Output is correct
26 Correct 254 ms 3412 KB Output is correct
27 Correct 246 ms 3668 KB Output is correct
28 Correct 233 ms 3240 KB Output is correct
29 Correct 245 ms 3152 KB Output is correct
30 Correct 245 ms 3424 KB Output is correct
31 Correct 241 ms 3132 KB Output is correct
32 Correct 237 ms 3164 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 251 ms 3100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 18264 KB Output is correct
2 Correct 65 ms 21744 KB Output is correct
3 Correct 57 ms 20304 KB Output is correct
4 Correct 57 ms 20116 KB Output is correct
5 Correct 60 ms 20744 KB Output is correct
6 Correct 56 ms 20188 KB Output is correct
7 Correct 62 ms 20048 KB Output is correct
8 Correct 62 ms 20352 KB Output is correct
9 Correct 61 ms 20052 KB Output is correct
10 Correct 73 ms 21588 KB Output is correct
11 Correct 149 ms 28192 KB Output is correct
12 Correct 174 ms 31312 KB Output is correct
13 Correct 148 ms 28204 KB Output is correct
14 Correct 144 ms 24584 KB Output is correct
15 Correct 164 ms 26708 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 56 ms 20724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 17496 KB Output is correct
2 Correct 63 ms 20816 KB Output is correct
3 Correct 61 ms 21076 KB Output is correct
4 Correct 65 ms 21336 KB Output is correct
5 Correct 67 ms 22088 KB Output is correct
6 Correct 56 ms 20056 KB Output is correct
7 Correct 60 ms 20560 KB Output is correct
8 Correct 62 ms 20560 KB Output is correct
9 Correct 71 ms 21328 KB Output is correct
10 Correct 67 ms 20484 KB Output is correct
11 Correct 168 ms 30384 KB Output is correct
12 Correct 165 ms 28756 KB Output is correct
13 Correct 152 ms 28296 KB Output is correct
14 Correct 152 ms 26448 KB Output is correct
15 Correct 144 ms 24448 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 59 ms 21536 KB Output is correct
18 Correct 8 ms 856 KB Output is correct
19 Correct 8 ms 984 KB Output is correct
20 Correct 12 ms 860 KB Output is correct
21 Correct 8 ms 860 KB Output is correct
22 Correct 8 ms 856 KB Output is correct
23 Correct 9 ms 856 KB Output is correct
24 Correct 8 ms 860 KB Output is correct
25 Correct 8 ms 980 KB Output is correct
26 Correct 9 ms 1008 KB Output is correct
27 Correct 8 ms 860 KB Output is correct
28 Correct 9 ms 1116 KB Output is correct
29 Correct 9 ms 1116 KB Output is correct
30 Correct 8 ms 1116 KB Output is correct
31 Correct 9 ms 856 KB Output is correct
32 Correct 9 ms 860 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 8 ms 1020 KB Output is correct
35 Correct 284 ms 3516 KB Output is correct
36 Correct 243 ms 3412 KB Output is correct
37 Correct 274 ms 3632 KB Output is correct
38 Correct 243 ms 3696 KB Output is correct
39 Correct 257 ms 3408 KB Output is correct
40 Correct 246 ms 3448 KB Output is correct
41 Correct 254 ms 3512 KB Output is correct
42 Correct 274 ms 3452 KB Output is correct
43 Correct 254 ms 3412 KB Output is correct
44 Correct 246 ms 3668 KB Output is correct
45 Correct 233 ms 3240 KB Output is correct
46 Correct 245 ms 3152 KB Output is correct
47 Correct 245 ms 3424 KB Output is correct
48 Correct 241 ms 3132 KB Output is correct
49 Correct 237 ms 3164 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 251 ms 3100 KB Output is correct
52 Correct 69 ms 18264 KB Output is correct
53 Correct 65 ms 21744 KB Output is correct
54 Correct 57 ms 20304 KB Output is correct
55 Correct 57 ms 20116 KB Output is correct
56 Correct 60 ms 20744 KB Output is correct
57 Correct 56 ms 20188 KB Output is correct
58 Correct 62 ms 20048 KB Output is correct
59 Correct 62 ms 20352 KB Output is correct
60 Correct 61 ms 20052 KB Output is correct
61 Correct 73 ms 21588 KB Output is correct
62 Correct 149 ms 28192 KB Output is correct
63 Correct 174 ms 31312 KB Output is correct
64 Correct 148 ms 28204 KB Output is correct
65 Correct 144 ms 24584 KB Output is correct
66 Correct 164 ms 26708 KB Output is correct
67 Correct 0 ms 348 KB Output is correct
68 Correct 56 ms 20724 KB Output is correct
69 Correct 394 ms 24084 KB Output is correct
70 Correct 385 ms 25288 KB Output is correct
71 Correct 389 ms 23636 KB Output is correct
72 Correct 391 ms 24656 KB Output is correct
73 Correct 382 ms 24404 KB Output is correct
74 Correct 382 ms 25424 KB Output is correct
75 Correct 390 ms 23924 KB Output is correct
76 Correct 397 ms 25752 KB Output is correct
77 Correct 361 ms 23632 KB Output is correct
78 Correct 401 ms 24400 KB Output is correct
79 Correct 420 ms 33668 KB Output is correct
80 Correct 401 ms 31560 KB Output is correct
81 Correct 409 ms 30908 KB Output is correct
82 Correct 394 ms 27728 KB Output is correct
83 Correct 399 ms 26792 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 330 ms 23880 KB Output is correct