답안 #584408

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
584408 2022-06-27T11:04:53 Z Koosha_mv Event Hopping (BOI22_events) C++14
10 / 100
1500 ms 8916 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[N][lg];
 
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[i][0]=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[i][0]=j;
			}
		}
	}
	f(i,1,n+1){
		f(l,1,lg){
			par[i][l]=par[par[i][l-1]][l-1];
		}
	}
	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 now=v,ans=1;
		f_(l,lg-1,0){
			if(t[u]<s[par[now][l]]){
				ans+=(1<<l);
				now=par[now][l];
			}
		}
		while(t[u]<s[now]){
			if(par[now][0]==now) break ;
			now=par[now][0];
			ans++;
		}
		//ans++,now=par[now][0];
		if(s[now]<=t[u]){
			cout<<ans<<'\n';
		}
		else{
			cout<<"impossible"<<'\n';
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Execution timed out 1588 ms 8812 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 4 ms 424 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 4 ms 340 KB Output is correct
6 Correct 4 ms 340 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 4 ms 424 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 4 ms 340 KB Output is correct
6 Correct 4 ms 340 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 4 ms 424 KB Output is correct
13 Correct 4 ms 340 KB Output is correct
14 Correct 4 ms 340 KB Output is correct
15 Correct 4 ms 340 KB Output is correct
16 Correct 5 ms 428 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1199 ms 1260 KB Output is correct
20 Execution timed out 1569 ms 1008 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 4 ms 424 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 4 ms 340 KB Output is correct
6 Correct 4 ms 340 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 0 ms 296 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 4 ms 340 KB Output is correct
13 Correct 5 ms 340 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 4 ms 340 KB Output is correct
16 Correct 5 ms 340 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Execution timed out 1586 ms 8916 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1588 ms 8852 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Execution timed out 1588 ms 8812 KB Time limit exceeded
3 Halted 0 ms 0 KB -