Submission #867735

# Submission time Handle Problem Language Result Execution time Memory
867735 2023-10-29T10:52:01 Z TAhmed33 Event Hopping (BOI22_events) C++
10 / 100
1500 ms 16712 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
const int MAXN = 2e5 + 25;
#define mid ((l + r) >> 1)
#define tl (node + 1)
#define tr (node + 2 * (mid - l + 1))
const int bad = 1e9;
struct SegmentTree {
	int tree[2 * MAXN];
	void init () {
		for (auto &i : tree) i = bad;
	}
	void update (int l, int r, int a, int b, int node) {
		if (l > a || r < a) return;
		if (l == r) {
			tree[node] = min(tree[node], b);
			return;
		}
		update(l, mid, a, b, tl);
		update(mid + 1, r, a, b, tr);
		tree[node] = min(tree[tl], tree[tr]);
	}
	int get (int l, int r, int a, int b, int node) {
		if (l > b || r < a) return bad;
		if (l >= a && r <= b) return tree[node];
		return min(get(l, mid, a, b, tl), get(mid + 1, r, a, b, tr));
	}
} cur;
vector <int> adj[MAXN];
vector <int> arr[MAXN];
vector <int> d;
int dp[MAXN];
vector <vector <int>> events;
int idxx[MAXN];
int main () {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, q;
	cin >> n >> q;
	for (int i = 1; i <= n; i++) {
		int l, r;
		cin >> l >> r;
		arr[i] = {l, r, i};
		d.push_back(l); d.push_back(r);
	}
	sort(d.begin(), d.end()); d.resize(unique(d.begin(), d.end()) - d.begin());
	for (int i = 1; i <= n; i++) {
		arr[i][0] = lower_bound(d.begin(), d.end(), arr[i][0]) - d.begin();
		arr[i][1] = lower_bound(d.begin(), d.end(), arr[i][1]) - d.begin();
		arr[i][0]++; arr[i][1]++;
	}
	sort(arr + 1, arr + n + 1, [] (vector <int> &a, vector <int> &b) {
		return a[1] == b[1] ? a[0] < b[0] : a[1] < b[1];
	});
	while (q--) {	
		int a, b;
		cin >> a >> b; 
		if (a == b) {
			cout << "0\n";
			continue;
		}
		cur.init();
		int ans = -1;
		for (int i = 1; i <= n; i++) {
			int l = arr[i][0], r = arr[i][1], idx = arr[i][2];
			if (idx == a) {
				cur.update(1, MAXN, r, 0, 1);
				continue;
			}
			if (idx == b) {
				ans = cur.get(1, MAXN, l, r, 1);
				break;
			}
			int x = cur.get(1, MAXN, l, r, 1);
			cur.update(1, MAXN, r, x + 1, 1);
		}		
		ans++;
		if (ans > n) {
			cout << "impossible\n";
		} else {
			cout << ans << '\n';
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Execution timed out 1582 ms 16688 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Correct 2 ms 12636 KB Output is correct
3 Correct 19 ms 12860 KB Output is correct
4 Correct 12 ms 12632 KB Output is correct
5 Correct 12 ms 12636 KB Output is correct
6 Correct 12 ms 12860 KB Output is correct
7 Correct 16 ms 12888 KB Output is correct
8 Correct 15 ms 12632 KB Output is correct
9 Correct 14 ms 12636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Correct 2 ms 12636 KB Output is correct
3 Correct 19 ms 12860 KB Output is correct
4 Correct 12 ms 12632 KB Output is correct
5 Correct 12 ms 12636 KB Output is correct
6 Correct 12 ms 12860 KB Output is correct
7 Correct 16 ms 12888 KB Output is correct
8 Correct 15 ms 12632 KB Output is correct
9 Correct 14 ms 12636 KB Output is correct
10 Correct 2 ms 12636 KB Output is correct
11 Correct 3 ms 12632 KB Output is correct
12 Correct 21 ms 12856 KB Output is correct
13 Correct 12 ms 12636 KB Output is correct
14 Correct 12 ms 12632 KB Output is correct
15 Correct 13 ms 12892 KB Output is correct
16 Correct 16 ms 12636 KB Output is correct
17 Correct 16 ms 12864 KB Output is correct
18 Correct 16 ms 12864 KB Output is correct
19 Execution timed out 1545 ms 13012 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Correct 2 ms 12636 KB Output is correct
3 Correct 19 ms 12860 KB Output is correct
4 Correct 12 ms 12632 KB Output is correct
5 Correct 12 ms 12636 KB Output is correct
6 Correct 12 ms 12860 KB Output is correct
7 Correct 16 ms 12888 KB Output is correct
8 Correct 15 ms 12632 KB Output is correct
9 Correct 14 ms 12636 KB Output is correct
10 Correct 2 ms 12632 KB Output is correct
11 Correct 3 ms 12888 KB Output is correct
12 Correct 20 ms 12868 KB Output is correct
13 Correct 12 ms 12636 KB Output is correct
14 Correct 12 ms 12864 KB Output is correct
15 Correct 13 ms 12636 KB Output is correct
16 Correct 16 ms 12632 KB Output is correct
17 Correct 14 ms 12632 KB Output is correct
18 Correct 14 ms 12864 KB Output is correct
19 Execution timed out 1594 ms 16712 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1519 ms 16588 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 12636 KB Output is correct
2 Execution timed out 1582 ms 16688 KB Time limit exceeded
3 Halted 0 ms 0 KB -