답안 #1031406

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1031406 2024-07-22T19:52:50 Z hasan2006 Event Hopping (BOI22_events) C++17
100 / 100
78 ms 28352 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 = 1e5 + 9 , mod = 1e9 + 7;
ll c[N] , d[N] , p[N][22]  , 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 59 ms 27876 KB Output is correct
3 Correct 60 ms 27836 KB Output is correct
4 Correct 66 ms 27856 KB Output is correct
5 Correct 62 ms 27836 KB Output is correct
6 Correct 60 ms 27580 KB Output is correct
7 Correct 63 ms 27584 KB Output is correct
8 Correct 52 ms 28352 KB Output is correct
9 Correct 52 ms 28204 KB Output is correct
10 Correct 75 ms 28096 KB Output is correct
11 Correct 65 ms 27320 KB Output is correct
12 Correct 45 ms 26884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 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 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 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 600 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 540 KB Output is correct
13 Correct 1 ms 732 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 21 ms 3100 KB Output is correct
20 Correct 18 ms 3100 KB Output is correct
21 Correct 25 ms 3356 KB Output is correct
22 Correct 18 ms 3344 KB Output is correct
23 Correct 17 ms 3344 KB Output is correct
24 Correct 15 ms 3356 KB Output is correct
25 Correct 17 ms 2840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 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 600 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 732 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 1 ms 536 KB Output is correct
16 Correct 1 ms 536 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 39 ms 25924 KB Output is correct
20 Correct 37 ms 25140 KB Output is correct
21 Correct 38 ms 24260 KB Output is correct
22 Correct 39 ms 25152 KB Output is correct
23 Correct 35 ms 24256 KB Output is correct
24 Correct 39 ms 25920 KB Output is correct
25 Correct 28 ms 23552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 27844 KB Output is correct
2 Correct 59 ms 27836 KB Output is correct
3 Correct 66 ms 27836 KB Output is correct
4 Correct 52 ms 28348 KB Output is correct
5 Correct 69 ms 28012 KB Output is correct
6 Correct 75 ms 27832 KB Output is correct
7 Correct 72 ms 27816 KB Output is correct
8 Correct 67 ms 27192 KB Output is correct
9 Correct 36 ms 24344 KB Output is correct
10 Correct 60 ms 27460 KB Output is correct
11 Correct 52 ms 27072 KB Output is correct
12 Correct 64 ms 27544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 59 ms 27876 KB Output is correct
3 Correct 60 ms 27836 KB Output is correct
4 Correct 66 ms 27856 KB Output is correct
5 Correct 62 ms 27836 KB Output is correct
6 Correct 60 ms 27580 KB Output is correct
7 Correct 63 ms 27584 KB Output is correct
8 Correct 52 ms 28352 KB Output is correct
9 Correct 52 ms 28204 KB Output is correct
10 Correct 75 ms 28096 KB Output is correct
11 Correct 65 ms 27320 KB Output is correct
12 Correct 45 ms 26884 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 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 600 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 540 KB Output is correct
25 Correct 1 ms 732 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 0 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 21 ms 3100 KB Output is correct
32 Correct 18 ms 3100 KB Output is correct
33 Correct 25 ms 3356 KB Output is correct
34 Correct 18 ms 3344 KB Output is correct
35 Correct 17 ms 3344 KB Output is correct
36 Correct 15 ms 3356 KB Output is correct
37 Correct 17 ms 2840 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 1 ms 600 KB Output is correct
40 Correct 1 ms 732 KB Output is correct
41 Correct 1 ms 600 KB Output is correct
42 Correct 0 ms 604 KB Output is correct
43 Correct 1 ms 536 KB Output is correct
44 Correct 1 ms 536 KB Output is correct
45 Correct 0 ms 604 KB Output is correct
46 Correct 0 ms 604 KB Output is correct
47 Correct 39 ms 25924 KB Output is correct
48 Correct 37 ms 25140 KB Output is correct
49 Correct 38 ms 24260 KB Output is correct
50 Correct 39 ms 25152 KB Output is correct
51 Correct 35 ms 24256 KB Output is correct
52 Correct 39 ms 25920 KB Output is correct
53 Correct 28 ms 23552 KB Output is correct
54 Correct 58 ms 27844 KB Output is correct
55 Correct 59 ms 27836 KB Output is correct
56 Correct 66 ms 27836 KB Output is correct
57 Correct 52 ms 28348 KB Output is correct
58 Correct 69 ms 28012 KB Output is correct
59 Correct 75 ms 27832 KB Output is correct
60 Correct 72 ms 27816 KB Output is correct
61 Correct 67 ms 27192 KB Output is correct
62 Correct 36 ms 24344 KB Output is correct
63 Correct 60 ms 27460 KB Output is correct
64 Correct 52 ms 27072 KB Output is correct
65 Correct 64 ms 27544 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 56 ms 27840 KB Output is correct
68 Correct 59 ms 27836 KB Output is correct
69 Correct 65 ms 27832 KB Output is correct
70 Correct 74 ms 27836 KB Output is correct
71 Correct 63 ms 27580 KB Output is correct
72 Correct 63 ms 27704 KB Output is correct
73 Correct 51 ms 28316 KB Output is correct
74 Correct 51 ms 28352 KB Output is correct
75 Correct 67 ms 28024 KB Output is correct
76 Correct 71 ms 27324 KB Output is correct
77 Correct 43 ms 26564 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 1 ms 536 KB Output is correct
80 Correct 1 ms 604 KB Output is correct
81 Correct 0 ms 604 KB Output is correct
82 Correct 0 ms 736 KB Output is correct
83 Correct 1 ms 604 KB Output is correct
84 Correct 1 ms 604 KB Output is correct
85 Correct 0 ms 604 KB Output is correct
86 Correct 21 ms 3132 KB Output is correct
87 Correct 18 ms 3100 KB Output is correct
88 Correct 25 ms 3424 KB Output is correct
89 Correct 18 ms 3352 KB Output is correct
90 Correct 16 ms 3356 KB Output is correct
91 Correct 16 ms 3356 KB Output is correct
92 Correct 18 ms 2844 KB Output is correct
93 Correct 41 ms 25900 KB Output is correct
94 Correct 36 ms 25276 KB Output is correct
95 Correct 38 ms 24252 KB Output is correct
96 Correct 38 ms 25264 KB Output is correct
97 Correct 34 ms 24256 KB Output is correct
98 Correct 39 ms 26048 KB Output is correct
99 Correct 28 ms 23744 KB Output is correct
100 Correct 74 ms 27880 KB Output is correct
101 Correct 78 ms 27836 KB Output is correct
102 Correct 62 ms 27068 KB Output is correct
103 Correct 56 ms 27632 KB Output is correct
104 Correct 51 ms 27068 KB Output is correct
105 Correct 57 ms 27636 KB Output is correct
106 Correct 66 ms 26976 KB Output is correct
107 Correct 77 ms 27164 KB Output is correct
108 Correct 58 ms 26304 KB Output is correct
109 Correct 66 ms 26268 KB Output is correct
110 Correct 57 ms 26048 KB Output is correct
111 Correct 59 ms 26196 KB Output is correct