Submission #600956

# Submission time Handle Problem Language Result Execution time Memory
600956 2022-07-21T09:33:57 Z CSQ31 Event Hopping (BOI22_events) C++17
0 / 100
1500 ms 2272 KB
#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(),a.end()
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
const int MAXN = 1e5+1;
int s[MAXN],e[MAXN];
bool check(int i,int j){ //got edge i->j?
	return s[j] <= e[i] && e[i] <= e[j];
}
int main()
{
	owo
	int n,q;
	cin>>n>>q;
	vector<int>crd;
	for(int i=0;i<n;i++)cin>>s[i]>>e[i];
	for(int i=0;i<n;i++){
		crd.push_back(s[i]);
		crd.push_back(e[i]);
	}
	sort(all(crd));
	crd.resize(unique(all(crd)) - crd.begin());
	for(int i=0;i<n;i++){
		//s[i] = lower_bound(all(crd),s[i]) - crd.begin()+1;
		//e[i] = lower_bound(all(crd),e[i]) - crd.begin()+1;
	}
	vector<int>pre(n);
	for(int i=0;i<n;i++){
		pre[i] = i;
		for(int j=0;j<n;j++){
			if(check(i,j) && e[j] > e[pre[i]])pre[i] = j;		
		}	
	}
	while(q--){
		int l,r;
		cin>>l>>r;
		l--;
		r--;
		int ans = 0;
		while(l != r){
			if(e[l] == e[pre[l]])break;
			if(e[pre[l]] < s[r])l = pre[l];
			else break;
			ans++;
		}
		if(l!=r && check(l,r)){	
			l=r;
			ans++;
		}		
		if(l!=r){
			for(int i=0;i<n;i++){
				if(check(l,i) && check(i,r)){
					ans+=2;
					l = r;
					break;
					
				}	
			}
		}
		if(l!=r)cout<<"impossible"<<'\n';
		else cout<<ans<<'\n';
	}
	
	
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1578 ms 2272 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 5 ms 356 KB Output is correct
4 Correct 4 ms 340 KB Output is correct
5 Incorrect 4 ms 340 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 5 ms 356 KB Output is correct
4 Correct 4 ms 340 KB Output is correct
5 Incorrect 4 ms 340 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 5 ms 356 KB Output is correct
4 Correct 4 ms 340 KB Output is correct
5 Incorrect 4 ms 340 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1570 ms 2256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1578 ms 2272 KB Time limit exceeded
3 Halted 0 ms 0 KB -