Submission #679556

# Submission time Handle Problem Language Result Execution time Memory
679556 2023-01-08T13:50:55 Z penguin133 Event Hopping (BOI22_events) C++17
0 / 100
136 ms 27148 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif

vector<int> lmao[100005];
int S[100005], E[100005], dist[100005];
int n, q;

int par[20][100005];

void solve(){
	cin >> n >> q;
	for(int i=1;i<=n;i++)cin >> S[i] >> E[i];
	set <pi> st;
	for(int i=1;i<=n;i++)st.insert({E[i], i});
	for(int i=1;i<=n;i++){
		set<pi> :: iterator it = st.lower_bound({S[i], 0});
		while(it != st.end()){
			pi tmp = *it;
			if(tmp.fi > E[i])break;
			par[0][tmp.se] = i;
			it++;
		}
	}
	for(int i=1;i<=19;i++)for(int j=1;j<=n;j++)par[i][j] = par[i-1][par[i-1][j]];
	while(q--){
		int x, y; cin >> x >> y;
		int ans = 0, cur = x;
		for(int i=19;i>=0;i--){
			if(par[i][cur] != 0 && par[i][cur] <= y)cur = par[i][cur], ans += (1 << i);
		}
		if(cur == y)cout << ans << '\n';
		else cout << "impossible\n";
	}
}

main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int tc = 1;
	//cin >> tc;
	for(int tc1=1;tc1<=tc;tc1++){
		// cout << "Case #" << tc1 << ": ";
		solve();
	}
}

Compilation message

events.cpp:45:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   45 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2772 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2784 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2784 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2784 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 136 ms 27148 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2772 KB Output isn't correct
2 Halted 0 ms 0 KB -