Submission #745885

# Submission time Handle Problem Language Result Execution time Memory
745885 2023-05-21T09:19:05 Z vjudge1 Event Hopping (BOI22_events) C++17
20 / 100
97 ms 13648 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

struct event {
	int st, en, id;
};

const int maxn = 100010;
int nxt[maxn][20];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, q;
	cin >> n >> q;
	vector<event> e(n+1);
	for (int i = 1; i <= n; i++) {
		cin >> e[i].st >> e[i].en;
		e[i].id = i;
	}
	e.push_back({ 0, (int)1e9 + 1 });
	for (int i = 0; i < 20; i++) {
		nxt[n + 1][i] = n + 1;
	}
	vector<int> pos(n + 1);
	sort(e.begin()+1, e.end(), [](event& a, event& b) {return a.en < b.en; });
	for (int i = n; i > 0; i--) {
		pos[e[i].id] = i;
		int l = i, r = n + 2;
		while (l + 1 < r) {
			int m = (l + r) / 2;
			if (e[m].st <= e[i].en)l = m;
			else r = m;
		}
		nxt[i][0] = l;
		for (int j = 1; j < 20; j++) {
			nxt[i][j] = nxt[nxt[i][j - 1]][j - 1];
		}
	}
	for (int i = 0; i < q; i++) {
		int s, e;
		cin >> s >> e;
		s = pos[s];
		e = pos[e];
		if (e == s) {
			cout << "0\n";
			continue;
		}
		if (e < s) {
			cout << "impossible\n";
			continue;
		}
		int ans = 0;
		for (int i = 19; i >= 0; i--) {
			if (nxt[s][i] < e) {
				ans += (1 << i);
				s = nxt[s][i];
			}
		}
		if (nxt[s][0] < e) {
			cout << "impossible\n";
			continue;
		}
		cout << ans + 1 << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 71 ms 10268 KB Output is correct
2 Correct 66 ms 10260 KB Output is correct
3 Correct 80 ms 10312 KB Output is correct
4 Correct 69 ms 10832 KB Output is correct
5 Correct 83 ms 10552 KB Output is correct
6 Correct 85 ms 10428 KB Output is correct
7 Correct 85 ms 13448 KB Output is correct
8 Correct 97 ms 13648 KB Output is correct
9 Correct 42 ms 11704 KB Output is correct
10 Correct 67 ms 13152 KB Output is correct
11 Correct 73 ms 12996 KB Output is correct
12 Correct 71 ms 13176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -