답안 #980795

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
980795 2024-05-12T12:25:12 Z OAleksa Event Hopping (BOI22_events) C++14
25 / 100
1500 ms 14704 KB
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
const int N = 1e5 + 69;
const int K = 18;
int st[8 * N];
int n, q, l[N], r[N];
int cl[N], cr[N];
int up[N][K];
void modify(int v, int tl, int tr, int p, int x) {
	if (tl == tr) {
		if (l[x] < l[st[v]]) 
			st[v] = x;
	}
	else {
		int mid = (tl + tr) / 2;
		if (p <= mid)
			modify(v * 2, tl, mid, p, x);
		else
			modify(v * 2 + 1, mid + 1, tr, p, x);
		if (l[st[v * 2]] < l[st[v * 2 + 1]])
			st[v] = st[v * 2];
		else
			st[v] = st[v * 2 + 1];
	}
}
int get(int v, int tl, int tr, int x, int y) {
	if (tl > y || tr < x)
		return 0;
	else if (tl >= x && tr <= y)
		return st[v];
	else {
		int mid = (tl + tr) / 2;
		int ll = get(v * 2, tl, mid, x, y);
		int rr = get(v * 2 + 1, mid + 1, tr, x, y);	
		if (l[ll] < l[rr])
			return ll;
		return rr;
	}
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int tt = 1;
  //cin >> tt;
	while (tt--) {		
		cin >> n >> q;
		vector<int> xs;
		for (int i = 1;i <= n;i++) {
			cin >> l[i] >> r[i];
			xs.push_back(l[i]);
			xs.push_back(r[i]);
		}
		l[0] = 1e9 + 10;
		sort(xs.begin(), xs.end());
		xs.erase(unique(xs.begin(), xs.end()), xs.end());
		vector<pair<int, int>> ord;
		for (int i = 1;i <= n;i++) {
			cl[i] = lower_bound(xs.begin(), xs.end(), l[i]) - xs.begin() + 1;
			cr[i] = lower_bound(xs.begin(), xs.end(), r[i]) - xs.begin() + 1;
			l[i] = cl[i];
			r[i] = cr[i];
			ord.push_back({l[i], i});
		}
		sort(ord.begin(), ord.end());
		const int m = 2 * n;
		for (int j = 0;j < n;j++) {
			int i = ord[j].s;
			int g = get(1, 1, m, l[i], r[i]);
			if (l[i] < l[g])
				up[i][0] = i;
			else
				up[i][0] = g;
			modify(1, 1, m, r[i], i);
		}
		for (int j = 1;j < K;j++) {
			for (int i = n;i >= 1;i--) {
				up[i][j] = up[up[i][j - 1]][j - 1];
			}
		}
		while (q--) {
			int x, y;
			cin >> x >> y;
			if (r[x] <= r[y] && l[up[y][K - 1]] <= r[x]) {
				int ans = 0;
				if (x == y) {
					cout << "0\n";
					continue;
				}
				while (l[y] > r[x]) {
					ans += 1;
					y = up[y][0];
				}
				cout << ans + 1 << '\n';
			}
			else 
				cout << "impossible\n";
		}
	}
  return 0; 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Execution timed out 1585 ms 12588 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4440 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 2 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 4440 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4440 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 2 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 4440 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 2 ms 4444 KB Output is correct
13 Correct 1 ms 4696 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 2 ms 4444 KB Output is correct
17 Correct 1 ms 4440 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 902 ms 8188 KB Output is correct
20 Execution timed out 1530 ms 8072 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4440 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 2 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 4440 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 2 ms 4444 KB Output is correct
12 Correct 2 ms 4444 KB Output is correct
13 Correct 3 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 2 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 2 ms 4444 KB Output is correct
19 Correct 253 ms 14512 KB Output is correct
20 Correct 129 ms 13740 KB Output is correct
21 Correct 93 ms 14416 KB Output is correct
22 Correct 87 ms 14488 KB Output is correct
23 Correct 103 ms 14704 KB Output is correct
24 Correct 95 ms 14628 KB Output is correct
25 Correct 42 ms 13648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1532 ms 12584 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Execution timed out 1585 ms 12588 KB Time limit exceeded
3 Halted 0 ms 0 KB -