답안 #1031405

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1031405 2024-07-22T19:50:42 Z hasan2006 Event Hopping (BOI22_events) C++17
100 / 100
78 ms 26816 KB
#include <bits/stdc++.h>

using namespace std;

#define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define rall(s) s.rbegin(),s.rend()
#define all(s) s.begin(),s.end()
#define pb push_back
#define se second
#define fi first
#define ll long long
#define ld long double
#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define yes cout<<"yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define no cout<<"no\n"


const int N = 5e5 + 9 , mod = 1e9 + 7;
ll a[N] , b[N] , dp[N] , c[N] , d[N] , p[N][20]  , S[N] , E[N] ;

void solve()
{
    ll n ,t , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mx = 0 , mn = 1e18;
	cin>>n>>q;
	vector<pair<ll,pair<ll,ll>>>v;
	for(i = 0; i < n; i++){
        cin>>x>>y;
        v.pb({y , {x , i}});
	}
	sort(all(v));
	for(i = 0; i < n; i++)
		c[v[i].se.se] = i;
	for(i = 0; i < n; i++)
		S[i] = v[i].se.fi , E[i] = v[i].fi;
	for (i = 0; i < n; i++)
		S[i] = (lower_bound(E, E + n, S[i]) - E);
	vector<ll>V;
	for(j = 0; j < n; j++){
		if(S[j] >= j)
			p[j][0] = j;
		else{
			auto it = lower_bound(V.begin(), V.end(), S[j]);
			assert(it != V.end());
			p[j][0] = *it;
		}
		for(i = 1; i < 20; i++)
			p[j][i] = p[p[j][i - 1]][i - 1];
		while (!V.empty() && S[V.back()] >= S[j])
			V.pop_back();
		V.push_back(j);
	}
	while(q--){
		cin>>s>>t;
		s = c[s - 1] , t = c[t - 1];
		if(s == t)
			cout<<0<<"\n";
		else {
			if(v[t].se.fi <= v[s].fi && v[s].fi <= v[t].fi)
				cout<<1<< "\n";
			else{
				if(s >= t){
					cout<<"impossible\n";
					continue;
				}
				x = 1;
				for(i = 19; i >= 0; i--)
					if(s < S[p[t][i]])
						t = p[t][i] , x += (1 << i);
				if(s < S[t])
					t = p[t][0] , x++;
				if(s >= S[t])
					cout<<x<<"\n";
				else
					cout<<"impossible\n";
			}
		}
	}
}

int main(){
    TL;
    /*#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif*/
    int t = 1;
    //   cin>>t;
    while(t--)
     {
        solve();
     }
}
// Author : حسن

Compilation message

events.cpp: In function 'void solve()':
events.cpp:26:26: warning: unused variable 'l' [-Wunused-variable]
   26 |     ll n ,t , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mx = 0 , mn = 1e18;
      |                          ^
events.cpp:26:29: warning: unused variable 'r' [-Wunused-variable]
   26 |     ll n ,t , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mx = 0 , mn = 1e18;
      |                             ^
events.cpp:26:49: warning: unused variable 'f' [-Wunused-variable]
   26 |     ll n ,t , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mx = 0 , mn = 1e18;
      |                                                 ^
events.cpp:26:53: warning: unused variable 'k' [-Wunused-variable]
   26 |     ll n ,t , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mx = 0 , mn = 1e18;
      |                                                     ^
events.cpp:26:57: warning: unused variable 'm' [-Wunused-variable]
   26 |     ll n ,t , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mx = 0 , mn = 1e18;
      |                                                         ^
events.cpp:26:61: warning: unused variable 'mx' [-Wunused-variable]
   26 |     ll n ,t , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mx = 0 , mn = 1e18;
      |                                                             ^~
events.cpp:26:70: warning: unused variable 'mn' [-Wunused-variable]
   26 |     ll n ,t , q , i , j ,l ,r , x , y , s = 0 , f , k , m , mx = 0 , mn = 1e18;
      |                                                                      ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 55 ms 26304 KB Output is correct
3 Correct 60 ms 26220 KB Output is correct
4 Correct 65 ms 26304 KB Output is correct
5 Correct 60 ms 26304 KB Output is correct
6 Correct 59 ms 26168 KB Output is correct
7 Correct 60 ms 26296 KB Output is correct
8 Correct 49 ms 26808 KB Output is correct
9 Correct 50 ms 26640 KB Output is correct
10 Correct 69 ms 26508 KB Output is correct
11 Correct 66 ms 25788 KB Output is correct
12 Correct 41 ms 25152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 732 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 732 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 728 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 21 ms 3088 KB Output is correct
20 Correct 19 ms 3096 KB Output is correct
21 Correct 25 ms 3348 KB Output is correct
22 Correct 18 ms 3320 KB Output is correct
23 Correct 19 ms 3100 KB Output is correct
24 Correct 19 ms 3100 KB Output is correct
25 Correct 18 ms 2844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 732 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 42 ms 24608 KB Output is correct
20 Correct 38 ms 23576 KB Output is correct
21 Correct 42 ms 22816 KB Output is correct
22 Correct 37 ms 23600 KB Output is correct
23 Correct 33 ms 22720 KB Output is correct
24 Correct 39 ms 24504 KB Output is correct
25 Correct 29 ms 22208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 26192 KB Output is correct
2 Correct 59 ms 26300 KB Output is correct
3 Correct 76 ms 26308 KB Output is correct
4 Correct 50 ms 26744 KB Output is correct
5 Correct 75 ms 26512 KB Output is correct
6 Correct 76 ms 26304 KB Output is correct
7 Correct 72 ms 26300 KB Output is correct
8 Correct 65 ms 25532 KB Output is correct
9 Correct 33 ms 22732 KB Output is correct
10 Correct 55 ms 26044 KB Output is correct
11 Correct 52 ms 25532 KB Output is correct
12 Correct 56 ms 26056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 55 ms 26304 KB Output is correct
3 Correct 60 ms 26220 KB Output is correct
4 Correct 65 ms 26304 KB Output is correct
5 Correct 60 ms 26304 KB Output is correct
6 Correct 59 ms 26168 KB Output is correct
7 Correct 60 ms 26296 KB Output is correct
8 Correct 49 ms 26808 KB Output is correct
9 Correct 50 ms 26640 KB Output is correct
10 Correct 69 ms 26508 KB Output is correct
11 Correct 66 ms 25788 KB Output is correct
12 Correct 41 ms 25152 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 732 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 600 KB Output is correct
28 Correct 1 ms 728 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 21 ms 3088 KB Output is correct
32 Correct 19 ms 3096 KB Output is correct
33 Correct 25 ms 3348 KB Output is correct
34 Correct 18 ms 3320 KB Output is correct
35 Correct 19 ms 3100 KB Output is correct
36 Correct 19 ms 3100 KB Output is correct
37 Correct 18 ms 2844 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 0 ms 604 KB Output is correct
46 Correct 1 ms 604 KB Output is correct
47 Correct 42 ms 24608 KB Output is correct
48 Correct 38 ms 23576 KB Output is correct
49 Correct 42 ms 22816 KB Output is correct
50 Correct 37 ms 23600 KB Output is correct
51 Correct 33 ms 22720 KB Output is correct
52 Correct 39 ms 24504 KB Output is correct
53 Correct 29 ms 22208 KB Output is correct
54 Correct 54 ms 26192 KB Output is correct
55 Correct 59 ms 26300 KB Output is correct
56 Correct 76 ms 26308 KB Output is correct
57 Correct 50 ms 26744 KB Output is correct
58 Correct 75 ms 26512 KB Output is correct
59 Correct 76 ms 26304 KB Output is correct
60 Correct 72 ms 26300 KB Output is correct
61 Correct 65 ms 25532 KB Output is correct
62 Correct 33 ms 22732 KB Output is correct
63 Correct 55 ms 26044 KB Output is correct
64 Correct 52 ms 25532 KB Output is correct
65 Correct 56 ms 26056 KB Output is correct
66 Correct 0 ms 344 KB Output is correct
67 Correct 55 ms 26352 KB Output is correct
68 Correct 58 ms 26300 KB Output is correct
69 Correct 63 ms 26208 KB Output is correct
70 Correct 65 ms 26208 KB Output is correct
71 Correct 78 ms 26044 KB Output is correct
72 Correct 59 ms 26304 KB Output is correct
73 Correct 49 ms 26816 KB Output is correct
74 Correct 49 ms 26816 KB Output is correct
75 Correct 73 ms 26652 KB Output is correct
76 Correct 62 ms 25788 KB Output is correct
77 Correct 46 ms 25024 KB Output is correct
78 Correct 1 ms 348 KB Output is correct
79 Correct 1 ms 680 KB Output is correct
80 Correct 1 ms 732 KB Output is correct
81 Correct 0 ms 604 KB Output is correct
82 Correct 1 ms 504 KB Output is correct
83 Correct 1 ms 728 KB Output is correct
84 Correct 1 ms 600 KB Output is correct
85 Correct 1 ms 604 KB Output is correct
86 Correct 21 ms 2884 KB Output is correct
87 Correct 19 ms 3096 KB Output is correct
88 Correct 25 ms 3172 KB Output is correct
89 Correct 17 ms 3356 KB Output is correct
90 Correct 20 ms 3096 KB Output is correct
91 Correct 15 ms 3100 KB Output is correct
92 Correct 17 ms 2844 KB Output is correct
93 Correct 37 ms 24508 KB Output is correct
94 Correct 34 ms 23740 KB Output is correct
95 Correct 35 ms 22716 KB Output is correct
96 Correct 38 ms 23744 KB Output is correct
97 Correct 32 ms 22720 KB Output is correct
98 Correct 38 ms 24512 KB Output is correct
99 Correct 27 ms 22212 KB Output is correct
100 Correct 69 ms 26304 KB Output is correct
101 Correct 68 ms 26352 KB Output is correct
102 Correct 60 ms 25588 KB Output is correct
103 Correct 56 ms 26048 KB Output is correct
104 Correct 54 ms 25536 KB Output is correct
105 Correct 55 ms 26040 KB Output is correct
106 Correct 63 ms 25552 KB Output is correct
107 Correct 69 ms 25788 KB Output is correct
108 Correct 62 ms 24672 KB Output is correct
109 Correct 56 ms 24768 KB Output is correct
110 Correct 57 ms 24508 KB Output is correct
111 Correct 56 ms 24508 KB Output is correct