답안 #584422

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
584422 2022-06-27T11:27:01 Z Koosha_mv Event Hopping (BOI22_events) C++14
0 / 100
28 ms 2772 KB
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
 
const int N=1e5+99,lg=20;
 
int n,q,s[N],t[N],par[lg][N];
 
int32_t main(){
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin>>n>>q;
	f(i,1,n+1){
		cin>>s[i]>>t[i];
		par[0][i]=i;
	}
	f(i,1,n+1){
		f(j,1,n+1){
			if(s[i]<=t[j] && t[j]<=t[i] && s[j]<s[par[i][0]]){
				par[0][i]=j;
			}
		}
	}
	f(i,1,n+1){
		f(l,1,lg){
			par[l][i]=par[l-1][par[l-1][i]];
		}
	}
	while(q--){
		int u,v;
		cin>>u>>v;
		if(u==v){
			cout<<0<<'\n';
			continue ;
		}
		if(s[v]<=t[u]){
			if(t[u]<=t[v]){
				cout<<1<<'\n';
			}
			else{
				cout<<"impossible"<<'\n';
			}
			continue ;
		}
		int ans=1;
		while(t[u]<s[v]){
			if(par[0][v]==v) break ;
			v=par[0][v];
			ans++;
		}
		if(s[v]<=t[u]){
			cout<<ans<<'\n';
		}
		else{
			cout<<"impossible"<<'\n';
		}
	}
}
/*
8 1
1 2
3 4
1 5
6 7
5 10
10 20
15 20
999999999 1000000000
1 6
*/
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 28 ms 2772 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -