답안 #744630

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
744630 2023-05-18T20:50:50 Z MohamedAhmed04 Osumnjičeni (COCI21_osumnjiceni) C++14
110 / 110
325 ms 35972 KB
#include <bits/stdc++.h>

using namespace std ;

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace __gnu_pbds;

template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update> ;

const int MAX = 2e5 + 10 ;

int L[MAX] , R[MAX] ;
int n , q ;

int val[MAX] , to[MAX][20] ;

void preprocess()
{
	set< array<int , 3> >s ;
	int last = 0 ;
	to[n+1][0] = n+1 ;
	for(int i = 1 ; i <= n ; ++i)
	{
		to[i][0] = n+1 ;
		auto it = s.lower_bound({L[i] , -1 , -1}) ;
		if(it != s.begin())
			--it ;
		while(it != s.end())
		{
			array<int , 3>a = *it ;
			if(a[0] > R[i])
				break ;
			if(a[1] >= L[i])
				val[i] = max(val[i] , a[2]) ;
			++it ;
		}
		for(int j = last+1 ; j <= val[i] ; ++j)
			s.erase({L[j] , R[j] , j}) ;
		last = max(last , val[i]) ;
		s.insert({L[i] , R[i] , i}) ;
		to[val[i]][0] = i ;
	}
	for(int i = n-1 ; i >= 1 ; --i)
		to[i][0] = min(to[i][0] , to[i+1][0]) ;
	for(int j = 1 ; j < 20 ; ++j)
	{
		for(int i = 1 ; i <= n+1 ; ++i)
			to[i][j] = to[to[i][j-1]][j-1] ;
	}
}

int solve(int l , int r)
{
	int ans = 1 ;
	for(int i = 19 ; i >= 0 ; --i)
	{
		if(to[l][i] <= r)
			ans += (1 << i) , l = to[l][i] ;
	}
	return ans ;
}

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n ;
	for(int i = 1 ; i <= n ; ++i)
		cin>>L[i]>>R[i] ;
	preprocess() ;
	cin>>q ;
	for(int i = 1 ; i <= q ; ++i)
	{
		int l , r ;
		cin>>l>>r ;
		cout<<solve(l , r)<<"\n" ;
	}
	return 0 ;
}		
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 17484 KB Output is correct
2 Correct 87 ms 20816 KB Output is correct
3 Correct 87 ms 20976 KB Output is correct
4 Correct 121 ms 21196 KB Output is correct
5 Correct 98 ms 22120 KB Output is correct
6 Correct 85 ms 20080 KB Output is correct
7 Correct 82 ms 20488 KB Output is correct
8 Correct 95 ms 20628 KB Output is correct
9 Correct 96 ms 21116 KB Output is correct
10 Correct 95 ms 20420 KB Output is correct
11 Correct 208 ms 32540 KB Output is correct
12 Correct 175 ms 30584 KB Output is correct
13 Correct 179 ms 30528 KB Output is correct
14 Correct 205 ms 27316 KB Output is correct
15 Correct 186 ms 25156 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 94 ms 21444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 724 KB Output is correct
2 Correct 4 ms 852 KB Output is correct
3 Correct 5 ms 904 KB Output is correct
4 Correct 4 ms 852 KB Output is correct
5 Correct 6 ms 852 KB Output is correct
6 Correct 4 ms 848 KB Output is correct
7 Correct 5 ms 852 KB Output is correct
8 Correct 4 ms 852 KB Output is correct
9 Correct 4 ms 852 KB Output is correct
10 Correct 6 ms 860 KB Output is correct
11 Correct 5 ms 1108 KB Output is correct
12 Correct 4 ms 1108 KB Output is correct
13 Correct 4 ms 1108 KB Output is correct
14 Correct 5 ms 980 KB Output is correct
15 Correct 5 ms 1108 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 3 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 724 KB Output is correct
2 Correct 4 ms 852 KB Output is correct
3 Correct 5 ms 904 KB Output is correct
4 Correct 4 ms 852 KB Output is correct
5 Correct 6 ms 852 KB Output is correct
6 Correct 4 ms 848 KB Output is correct
7 Correct 5 ms 852 KB Output is correct
8 Correct 4 ms 852 KB Output is correct
9 Correct 4 ms 852 KB Output is correct
10 Correct 6 ms 860 KB Output is correct
11 Correct 5 ms 1108 KB Output is correct
12 Correct 4 ms 1108 KB Output is correct
13 Correct 4 ms 1108 KB Output is correct
14 Correct 5 ms 980 KB Output is correct
15 Correct 5 ms 1108 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 3 ms 980 KB Output is correct
18 Correct 70 ms 3532 KB Output is correct
19 Correct 76 ms 3280 KB Output is correct
20 Correct 74 ms 3520 KB Output is correct
21 Correct 61 ms 3296 KB Output is correct
22 Correct 63 ms 3404 KB Output is correct
23 Correct 73 ms 3308 KB Output is correct
24 Correct 66 ms 3496 KB Output is correct
25 Correct 73 ms 3496 KB Output is correct
26 Correct 64 ms 3420 KB Output is correct
27 Correct 63 ms 3276 KB Output is correct
28 Correct 65 ms 3184 KB Output is correct
29 Correct 53 ms 3272 KB Output is correct
30 Correct 51 ms 3256 KB Output is correct
31 Correct 56 ms 3092 KB Output is correct
32 Correct 66 ms 3152 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 56 ms 3252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 99 ms 18204 KB Output is correct
2 Correct 94 ms 21692 KB Output is correct
3 Correct 96 ms 20300 KB Output is correct
4 Correct 88 ms 19940 KB Output is correct
5 Correct 93 ms 20672 KB Output is correct
6 Correct 86 ms 20272 KB Output is correct
7 Correct 89 ms 20044 KB Output is correct
8 Correct 92 ms 20200 KB Output is correct
9 Correct 93 ms 20096 KB Output is correct
10 Correct 116 ms 21580 KB Output is correct
11 Correct 178 ms 30336 KB Output is correct
12 Correct 204 ms 33240 KB Output is correct
13 Correct 201 ms 30288 KB Output is correct
14 Correct 213 ms 25272 KB Output is correct
15 Correct 210 ms 27596 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 80 ms 20584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 17484 KB Output is correct
2 Correct 87 ms 20816 KB Output is correct
3 Correct 87 ms 20976 KB Output is correct
4 Correct 121 ms 21196 KB Output is correct
5 Correct 98 ms 22120 KB Output is correct
6 Correct 85 ms 20080 KB Output is correct
7 Correct 82 ms 20488 KB Output is correct
8 Correct 95 ms 20628 KB Output is correct
9 Correct 96 ms 21116 KB Output is correct
10 Correct 95 ms 20420 KB Output is correct
11 Correct 208 ms 32540 KB Output is correct
12 Correct 175 ms 30584 KB Output is correct
13 Correct 179 ms 30528 KB Output is correct
14 Correct 205 ms 27316 KB Output is correct
15 Correct 186 ms 25156 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 94 ms 21444 KB Output is correct
18 Correct 4 ms 724 KB Output is correct
19 Correct 4 ms 852 KB Output is correct
20 Correct 5 ms 904 KB Output is correct
21 Correct 4 ms 852 KB Output is correct
22 Correct 6 ms 852 KB Output is correct
23 Correct 4 ms 848 KB Output is correct
24 Correct 5 ms 852 KB Output is correct
25 Correct 4 ms 852 KB Output is correct
26 Correct 4 ms 852 KB Output is correct
27 Correct 6 ms 860 KB Output is correct
28 Correct 5 ms 1108 KB Output is correct
29 Correct 4 ms 1108 KB Output is correct
30 Correct 4 ms 1108 KB Output is correct
31 Correct 5 ms 980 KB Output is correct
32 Correct 5 ms 1108 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 3 ms 980 KB Output is correct
35 Correct 70 ms 3532 KB Output is correct
36 Correct 76 ms 3280 KB Output is correct
37 Correct 74 ms 3520 KB Output is correct
38 Correct 61 ms 3296 KB Output is correct
39 Correct 63 ms 3404 KB Output is correct
40 Correct 73 ms 3308 KB Output is correct
41 Correct 66 ms 3496 KB Output is correct
42 Correct 73 ms 3496 KB Output is correct
43 Correct 64 ms 3420 KB Output is correct
44 Correct 63 ms 3276 KB Output is correct
45 Correct 65 ms 3184 KB Output is correct
46 Correct 53 ms 3272 KB Output is correct
47 Correct 51 ms 3256 KB Output is correct
48 Correct 56 ms 3092 KB Output is correct
49 Correct 66 ms 3152 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 56 ms 3252 KB Output is correct
52 Correct 99 ms 18204 KB Output is correct
53 Correct 94 ms 21692 KB Output is correct
54 Correct 96 ms 20300 KB Output is correct
55 Correct 88 ms 19940 KB Output is correct
56 Correct 93 ms 20672 KB Output is correct
57 Correct 86 ms 20272 KB Output is correct
58 Correct 89 ms 20044 KB Output is correct
59 Correct 92 ms 20200 KB Output is correct
60 Correct 93 ms 20096 KB Output is correct
61 Correct 116 ms 21580 KB Output is correct
62 Correct 178 ms 30336 KB Output is correct
63 Correct 204 ms 33240 KB Output is correct
64 Correct 201 ms 30288 KB Output is correct
65 Correct 213 ms 25272 KB Output is correct
66 Correct 210 ms 27596 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 80 ms 20584 KB Output is correct
69 Correct 288 ms 24068 KB Output is correct
70 Correct 284 ms 25304 KB Output is correct
71 Correct 290 ms 23516 KB Output is correct
72 Correct 266 ms 24780 KB Output is correct
73 Correct 260 ms 24344 KB Output is correct
74 Correct 296 ms 25780 KB Output is correct
75 Correct 298 ms 23864 KB Output is correct
76 Correct 325 ms 25600 KB Output is correct
77 Correct 300 ms 23808 KB Output is correct
78 Correct 248 ms 24164 KB Output is correct
79 Correct 248 ms 35972 KB Output is correct
80 Correct 277 ms 33452 KB Output is correct
81 Correct 249 ms 33208 KB Output is correct
82 Correct 254 ms 28364 KB Output is correct
83 Correct 266 ms 27340 KB Output is correct
84 Correct 1 ms 336 KB Output is correct
85 Correct 162 ms 23832 KB Output is correct