Submission #791955

# Submission time Handle Problem Language Result Execution time Memory
791955 2023-07-24T13:02:13 Z ToniB Event Hopping (BOI22_events) C++17
0 / 100
1500 ms 14532 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 2;
const int LOG = 17;

int n, q, s[MAXN], e[MAXN], bl[MAXN][LOG];
set<pair<int, int> > st;
vector<pair<int, bool> > v[MAXN];

int main(){
	cin >> n >> q;
	unordered_map<int, int> um;
	vector<int> cmp;
	for(int i = 0; i < n; ++i){
		cin >> s[i] >> e[i];
		cmp.push_back(s[i]);
		cmp.push_back(e[i]);
	}
	sort(cmp.begin(), cmp.end());
	cmp.erase(unique(cmp.begin(), cmp.end()), cmp.end());
	for(int i = 0; i < (int)cmp.size(); ++i){
		um[cmp[i]] = i;
	}
	for(int i = 0; i < n; ++i){
		s[i] = um[s[i]]; e[i] = um[e[i]];
		v[s[i]].push_back({i, 0});
		v[e[i]].push_back({i, 1});
	}
	
	for(int i = 0; i < n; ++i){
		int mini = 2 * n, idx = 0;
		for(int j = 0; j < n; ++j){
			if(s[i] <= e[j] && e[j] <= e[i]){
				if(s[j] < mini){
					mini = s[j];
					idx = j;
				}
			}
		}
		bl[i][0] = idx;
	}
	
	for(int j = 1; j < LOG; ++j){
		for(int i = 0; i < n; ++i){
			bl[i][j] = bl[bl[i][j - 1]][j - 1];
		}
	}
	while(q--){
		int qs, qe; cin >> qs >> qe, --qs, --qe;
		if(qs == qe){
			cout << "0\n"; continue;
		} else if(s[qs] <= s[qe] && s[qe] <= e[qs]){
			cout << "1\n"; continue;
		} else if(e[qs] > e[qe]){
			cout << "impossible\n"; continue;
		}

		int ret = 0;
		for(int i = LOG - 1; i >= 0; --i){
			int idx = bl[qe][i];
			if(e[qs] < s[idx]){
				qe = idx;
				ret += 1 << i;
			}
		}
		if(e[qs] < s[bl[qe][0]]) cout << "impossible\n";
		else cout << ret + 2 << "\n";
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Execution timed out 1584 ms 14460 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 6 ms 5076 KB Output is correct
4 Correct 6 ms 5076 KB Output is correct
5 Correct 6 ms 5076 KB Output is correct
6 Incorrect 6 ms 5076 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 6 ms 5076 KB Output is correct
4 Correct 6 ms 5076 KB Output is correct
5 Correct 6 ms 5076 KB Output is correct
6 Incorrect 6 ms 5076 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 6 ms 5076 KB Output is correct
4 Correct 6 ms 5076 KB Output is correct
5 Correct 6 ms 5076 KB Output is correct
6 Incorrect 6 ms 5076 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1571 ms 14532 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Execution timed out 1584 ms 14460 KB Time limit exceeded
3 Halted 0 ms 0 KB -