답안 #863066

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
863066 2023-10-19T14:25:52 Z Ahmed_Solyman Osumnjičeni (COCI21_osumnjiceni) C++14
110 / 110
454 ms 56540 KB
/*
In the name of Allah
made by: Ahmed_Solyman
*/
#include <bits/stdc++.h>
#include <ext/rope>
 
using namespace std;
using namespace __gnu_cxx;
#pragma GCC optimize("-Ofast")
#pragma GCC optimize("-O1")
//-------------------------------------------------------------//
typedef long long ll;
typedef unsigned long long ull;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI acos(-1)
#define lb lower_bound
#define ub upper_bound
#define endl '\n'
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define sum_to(n) (n*(n+1))/2
#define pb push_back
#define pf push_front
#define fil(arr,x) memset(arr,x,sizeof(arr))
const ll mod=1e9+7;
int dx[8]={0,1,0,-1,1,1,-1,-1};
int dy[8]={1,0,-1,0,1,-1,-1,1};
//-------------------------------------------------------------//
ll lcm(ll a,ll b)
{
    return (max(a,b)/__gcd(a,b))*min(a,b);
}
void person_bool(bool x)
{
    cout<<(x?"YES":"NO")<<endl;
}
const int N=2e5+5;
int l[N],r[N],dp[N][21];
struct segtree{
	vector<int>tree,lazy;
	int size;
	void init(int n){
		size=n;
		lazy.assign(n*4+5,-1);
		tree.assign(n*4+5,1e9);
	}
	void push_lazy(int l,int r,int p){
		if(lazy[p]!=-1){
			tree[p]=lazy[p];
			if(l!=r){
				lazy[p*2]=lazy[p];
				lazy[p*2+1]=lazy[p];
			}
			lazy[p]=-1;
		}
	}
	void set(int l,int r,int p,int lq,int rq,int v){
		push_lazy(l,r,p);
		if(l>=lq && r<=rq){
			lazy[p]=v;
			push_lazy(l,r,p);
			return;
		}
		if(r<lq || l>rq){
			return;
		}
		int mid=(l+r)/2;
		set(l,mid,p*2,lq,rq,v);
		set(mid+1,r,p*2+1,lq,rq,v);
		tree[p]=min(tree[p*2],tree[p*2+1]);
	}
	void set(int l,int r,int v){
		set(1,size,1,l,r,v);
	}
	int query(int l,int r,int p,int l_q,int r_q){
		push_lazy(l,r,p);
		if(l>=l_q && r<=r_q){
			return tree[p];
		}
		if(r<l_q || l>r_q){
			return 1e9;
		}
		int mid=(l+r)/2;
		return min(query(l,mid,p*2,l_q,r_q),query(mid+1,r,p*2+1,l_q,r_q));
	}
	int query(int l,int r){
		return query(1,size,1,l,r);
	}
};
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #ifndef ONLINE_JUDGE
  	//freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);
    #endif
    fast
    int n;cin>>n;
	vector<int>v;
    for(int i=1;i<=n;i++){
    	cin>>l[i]>>r[i];
    	v.push_back(l[i]);
    	v.push_back(r[i]);
    }
    sort(all(v));
    int cnt=1;
    unordered_map<int,int>mp;
    for(auto i:v){
    	mp[i]=cnt++;
    }
    for(int i=1;i<=n;i++){
    	l[i]=mp[l[i]];
    	r[i]=mp[r[i]];
    }
    cnt++;
    segtree s;
    s.init(4e5+5);
    s.set(1,4e5+5,n+1);
    for(int i=n;i>=1;i--){
    	dp[i][0]=s.query(l[i],r[i]);
    	dp[i][0]=min(dp[i][0],n+1);
    	if(i<n)dp[i][0]=min(dp[i][0],dp[i+1][0]);
    	s.set(l[i],r[i],i);
    }
    dp[n+1][0]=n+1;
    for(int j=1;j<=20;j++){
    	for(int i=1;i<=n+1;i++){
    		dp[i][j]=dp[dp[i][j-1]][j-1];
    	}
    }
    int q;cin>>q;
    while(q--){
    	int a,b;cin>>a>>b;
    	int ans=1;
    	for(int i=20;i>=0;i--){
    		if(dp[a][i]<=b){
    			a=dp[a][i];
    			ans+=(1<<i);
    		}
    	}
    	cout<<ans<<endl;
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 384 ms 49984 KB Output is correct
2 Correct 366 ms 51936 KB Output is correct
3 Correct 336 ms 51908 KB Output is correct
4 Correct 381 ms 52160 KB Output is correct
5 Correct 393 ms 52928 KB Output is correct
6 Correct 101 ms 34504 KB Output is correct
7 Correct 104 ms 34504 KB Output is correct
8 Correct 107 ms 34720 KB Output is correct
9 Correct 111 ms 34760 KB Output is correct
10 Correct 134 ms 34572 KB Output is correct
11 Correct 274 ms 52224 KB Output is correct
12 Correct 254 ms 51944 KB Output is correct
13 Correct 243 ms 51692 KB Output is correct
14 Correct 234 ms 52940 KB Output is correct
15 Correct 248 ms 52720 KB Output is correct
16 Correct 4 ms 14940 KB Output is correct
17 Correct 118 ms 35780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 17756 KB Output is correct
2 Correct 11 ms 17572 KB Output is correct
3 Correct 11 ms 17964 KB Output is correct
4 Correct 12 ms 17500 KB Output is correct
5 Correct 13 ms 17496 KB Output is correct
6 Correct 10 ms 17244 KB Output is correct
7 Correct 9 ms 17244 KB Output is correct
8 Correct 7 ms 17496 KB Output is correct
9 Correct 9 ms 17244 KB Output is correct
10 Correct 8 ms 17240 KB Output is correct
11 Correct 9 ms 17736 KB Output is correct
12 Correct 9 ms 17496 KB Output is correct
13 Correct 10 ms 17496 KB Output is correct
14 Correct 9 ms 17500 KB Output is correct
15 Correct 9 ms 17500 KB Output is correct
16 Correct 4 ms 14912 KB Output is correct
17 Correct 7 ms 17440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 17756 KB Output is correct
2 Correct 11 ms 17572 KB Output is correct
3 Correct 11 ms 17964 KB Output is correct
4 Correct 12 ms 17500 KB Output is correct
5 Correct 13 ms 17496 KB Output is correct
6 Correct 10 ms 17244 KB Output is correct
7 Correct 9 ms 17244 KB Output is correct
8 Correct 7 ms 17496 KB Output is correct
9 Correct 9 ms 17244 KB Output is correct
10 Correct 8 ms 17240 KB Output is correct
11 Correct 9 ms 17736 KB Output is correct
12 Correct 9 ms 17496 KB Output is correct
13 Correct 10 ms 17496 KB Output is correct
14 Correct 9 ms 17500 KB Output is correct
15 Correct 9 ms 17500 KB Output is correct
16 Correct 4 ms 14912 KB Output is correct
17 Correct 7 ms 17440 KB Output is correct
18 Correct 62 ms 18488 KB Output is correct
19 Correct 62 ms 18396 KB Output is correct
20 Correct 62 ms 18404 KB Output is correct
21 Correct 58 ms 18444 KB Output is correct
22 Correct 59 ms 18512 KB Output is correct
23 Correct 57 ms 18256 KB Output is correct
24 Correct 61 ms 18196 KB Output is correct
25 Correct 56 ms 17996 KB Output is correct
26 Correct 54 ms 18012 KB Output is correct
27 Correct 51 ms 18024 KB Output is correct
28 Correct 41 ms 18000 KB Output is correct
29 Correct 42 ms 18000 KB Output is correct
30 Correct 42 ms 18012 KB Output is correct
31 Correct 42 ms 18004 KB Output is correct
32 Correct 42 ms 18012 KB Output is correct
33 Correct 4 ms 14936 KB Output is correct
34 Correct 44 ms 18260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 392 ms 50664 KB Output is correct
2 Correct 361 ms 52712 KB Output is correct
3 Correct 330 ms 51432 KB Output is correct
4 Correct 343 ms 51640 KB Output is correct
5 Correct 394 ms 51724 KB Output is correct
6 Correct 103 ms 34532 KB Output is correct
7 Correct 107 ms 34492 KB Output is correct
8 Correct 104 ms 34504 KB Output is correct
9 Correct 106 ms 34500 KB Output is correct
10 Correct 116 ms 34752 KB Output is correct
11 Correct 219 ms 51444 KB Output is correct
12 Correct 240 ms 53444 KB Output is correct
13 Correct 231 ms 51628 KB Output is correct
14 Correct 254 ms 52936 KB Output is correct
15 Correct 239 ms 53184 KB Output is correct
16 Correct 3 ms 14936 KB Output is correct
17 Correct 102 ms 35468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 384 ms 49984 KB Output is correct
2 Correct 366 ms 51936 KB Output is correct
3 Correct 336 ms 51908 KB Output is correct
4 Correct 381 ms 52160 KB Output is correct
5 Correct 393 ms 52928 KB Output is correct
6 Correct 101 ms 34504 KB Output is correct
7 Correct 104 ms 34504 KB Output is correct
8 Correct 107 ms 34720 KB Output is correct
9 Correct 111 ms 34760 KB Output is correct
10 Correct 134 ms 34572 KB Output is correct
11 Correct 274 ms 52224 KB Output is correct
12 Correct 254 ms 51944 KB Output is correct
13 Correct 243 ms 51692 KB Output is correct
14 Correct 234 ms 52940 KB Output is correct
15 Correct 248 ms 52720 KB Output is correct
16 Correct 4 ms 14940 KB Output is correct
17 Correct 118 ms 35780 KB Output is correct
18 Correct 11 ms 17756 KB Output is correct
19 Correct 11 ms 17572 KB Output is correct
20 Correct 11 ms 17964 KB Output is correct
21 Correct 12 ms 17500 KB Output is correct
22 Correct 13 ms 17496 KB Output is correct
23 Correct 10 ms 17244 KB Output is correct
24 Correct 9 ms 17244 KB Output is correct
25 Correct 7 ms 17496 KB Output is correct
26 Correct 9 ms 17244 KB Output is correct
27 Correct 8 ms 17240 KB Output is correct
28 Correct 9 ms 17736 KB Output is correct
29 Correct 9 ms 17496 KB Output is correct
30 Correct 10 ms 17496 KB Output is correct
31 Correct 9 ms 17500 KB Output is correct
32 Correct 9 ms 17500 KB Output is correct
33 Correct 4 ms 14912 KB Output is correct
34 Correct 7 ms 17440 KB Output is correct
35 Correct 62 ms 18488 KB Output is correct
36 Correct 62 ms 18396 KB Output is correct
37 Correct 62 ms 18404 KB Output is correct
38 Correct 58 ms 18444 KB Output is correct
39 Correct 59 ms 18512 KB Output is correct
40 Correct 57 ms 18256 KB Output is correct
41 Correct 61 ms 18196 KB Output is correct
42 Correct 56 ms 17996 KB Output is correct
43 Correct 54 ms 18012 KB Output is correct
44 Correct 51 ms 18024 KB Output is correct
45 Correct 41 ms 18000 KB Output is correct
46 Correct 42 ms 18000 KB Output is correct
47 Correct 42 ms 18012 KB Output is correct
48 Correct 42 ms 18004 KB Output is correct
49 Correct 42 ms 18012 KB Output is correct
50 Correct 4 ms 14936 KB Output is correct
51 Correct 44 ms 18260 KB Output is correct
52 Correct 392 ms 50664 KB Output is correct
53 Correct 361 ms 52712 KB Output is correct
54 Correct 330 ms 51432 KB Output is correct
55 Correct 343 ms 51640 KB Output is correct
56 Correct 394 ms 51724 KB Output is correct
57 Correct 103 ms 34532 KB Output is correct
58 Correct 107 ms 34492 KB Output is correct
59 Correct 104 ms 34504 KB Output is correct
60 Correct 106 ms 34500 KB Output is correct
61 Correct 116 ms 34752 KB Output is correct
62 Correct 219 ms 51444 KB Output is correct
63 Correct 240 ms 53444 KB Output is correct
64 Correct 231 ms 51628 KB Output is correct
65 Correct 254 ms 52936 KB Output is correct
66 Correct 239 ms 53184 KB Output is correct
67 Correct 3 ms 14936 KB Output is correct
68 Correct 102 ms 35468 KB Output is correct
69 Correct 418 ms 55412 KB Output is correct
70 Correct 453 ms 56540 KB Output is correct
71 Correct 436 ms 55044 KB Output is correct
72 Correct 454 ms 55756 KB Output is correct
73 Correct 452 ms 55760 KB Output is correct
74 Correct 200 ms 38820 KB Output is correct
75 Correct 190 ms 38204 KB Output is correct
76 Correct 216 ms 38908 KB Output is correct
77 Correct 241 ms 38256 KB Output is correct
78 Correct 197 ms 38352 KB Output is correct
79 Correct 284 ms 55336 KB Output is correct
80 Correct 268 ms 54044 KB Output is correct
81 Correct 285 ms 54072 KB Output is correct
82 Correct 288 ms 55088 KB Output is correct
83 Correct 256 ms 54120 KB Output is correct
84 Correct 4 ms 14940 KB Output is correct
85 Correct 157 ms 38604 KB Output is correct