답안 #930344

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
930344 2024-02-19T12:14:39 Z NK_ Osumnjičeni (COCI21_osumnjiceni) C++17
110 / 110
345 ms 31932 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;

#define nl '\n'
#define f first
#define s second
#define mp make_pair

template<class T> using V = vector<T>;
using pi = pair<int, int>;
using vi = V<int>;
using vpi = V<pi>;

const int LG = 18;
int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int N; cin >> N;

	/*vi L(N), R(N); for(int i = 0; i < N; i++) cin >> L[i] >> R[i];

	int M = -1;
	{
		map<int, int> mp; int cur = 0;
		for(auto& x : L) mp[x]++; 
		for(auto& x : R) mp[x]++;
		for(auto& x : mp) x.second = cur++;
		for(auto& x : L) x = mp[x];
		for(auto& x : R) x = mp[x];
		M = cur;
	}*/
	vpi A(N); for(int i = 0; i < N; i++) cin >> A[i].f >> A[i].s;
	
	set<pi> S;

	auto add = [&](pi x) {

		auto it = S.lower_bound(x);

		if (it != end(S)) {
			pi y = *it;
			if (x.s >= y.f) return false;
		}

		if (it != begin(S)) {
			pi y = *prev(it);
			if (y.s >= x.f) return false;
		}	

		S.insert(x);
		return true;
	};

	V<vi> nxt(N + 1, vi(LG, N)); int bnd = 0;
	for(int i = 0; i < N; i++) {
		// cout << i << " ==> " << L[i] << " " << R[i] << endl;
		while(bnd < N && add(A[bnd])) bnd++;

		nxt[i][0] = bnd;
		// cout << i << " => " << bnd << endl;
		S.erase(A[i]);
	}

	for(int x = N - 1; x >= 0; x--) {
		for(int i = 1; i < LG; i++) nxt[x][i] = nxt[nxt[x][i-1]][i-1];
	}

	int Q; cin >> Q;
	for(int q = 0; q < Q; q++) {
		int l, r; cin >> l >> r; --l, --r;

		int ans = 0;
		for(int i = LG - 1; i >= 0; i--) {
			if (nxt[l][i] <= r) { ans += (1 << i); l = nxt[l][i]; }
		}

		cout << ans + 1 << nl;
	}



	exit(0-0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 21340 KB Output is correct
2 Correct 58 ms 21072 KB Output is correct
3 Correct 57 ms 21072 KB Output is correct
4 Correct 58 ms 21328 KB Output is correct
5 Correct 62 ms 22104 KB Output is correct
6 Correct 56 ms 20056 KB Output is correct
7 Correct 59 ms 20568 KB Output is correct
8 Correct 58 ms 20828 KB Output is correct
9 Correct 68 ms 21096 KB Output is correct
10 Correct 65 ms 20560 KB Output is correct
11 Correct 157 ms 30856 KB Output is correct
12 Correct 151 ms 29008 KB Output is correct
13 Correct 153 ms 29008 KB Output is correct
14 Correct 145 ms 26964 KB Output is correct
15 Correct 138 ms 25256 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 59 ms 21528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 860 KB Output is correct
2 Correct 3 ms 860 KB Output is correct
3 Correct 3 ms 860 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 3 ms 860 KB Output is correct
6 Correct 3 ms 860 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 3 ms 856 KB Output is correct
9 Correct 3 ms 856 KB Output is correct
10 Correct 4 ms 856 KB Output is correct
11 Correct 4 ms 1112 KB Output is correct
12 Correct 4 ms 1116 KB Output is correct
13 Correct 4 ms 1116 KB Output is correct
14 Correct 4 ms 860 KB Output is correct
15 Correct 4 ms 860 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 3 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 860 KB Output is correct
2 Correct 3 ms 860 KB Output is correct
3 Correct 3 ms 860 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 3 ms 860 KB Output is correct
6 Correct 3 ms 860 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 3 ms 856 KB Output is correct
9 Correct 3 ms 856 KB Output is correct
10 Correct 4 ms 856 KB Output is correct
11 Correct 4 ms 1112 KB Output is correct
12 Correct 4 ms 1116 KB Output is correct
13 Correct 4 ms 1116 KB Output is correct
14 Correct 4 ms 860 KB Output is correct
15 Correct 4 ms 860 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 3 ms 860 KB Output is correct
18 Correct 61 ms 1608 KB Output is correct
19 Correct 56 ms 1620 KB Output is correct
20 Correct 61 ms 1872 KB Output is correct
21 Correct 59 ms 1616 KB Output is correct
22 Correct 59 ms 1620 KB Output is correct
23 Correct 60 ms 1704 KB Output is correct
24 Correct 65 ms 1620 KB Output is correct
25 Correct 62 ms 1616 KB Output is correct
26 Correct 63 ms 1616 KB Output is correct
27 Correct 67 ms 1616 KB Output is correct
28 Correct 37 ms 1368 KB Output is correct
29 Correct 37 ms 1392 KB Output is correct
30 Correct 40 ms 1448 KB Output is correct
31 Correct 38 ms 1372 KB Output is correct
32 Correct 37 ms 1372 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 41 ms 1880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 22260 KB Output is correct
2 Correct 60 ms 21888 KB Output is correct
3 Correct 61 ms 20300 KB Output is correct
4 Correct 60 ms 20056 KB Output is correct
5 Correct 57 ms 20828 KB Output is correct
6 Correct 55 ms 20324 KB Output is correct
7 Correct 56 ms 20172 KB Output is correct
8 Correct 58 ms 20456 KB Output is correct
9 Correct 68 ms 20472 KB Output is correct
10 Correct 71 ms 21844 KB Output is correct
11 Correct 149 ms 28912 KB Output is correct
12 Correct 179 ms 31932 KB Output is correct
13 Correct 156 ms 28832 KB Output is correct
14 Correct 149 ms 25176 KB Output is correct
15 Correct 155 ms 27220 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 55 ms 20996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 21340 KB Output is correct
2 Correct 58 ms 21072 KB Output is correct
3 Correct 57 ms 21072 KB Output is correct
4 Correct 58 ms 21328 KB Output is correct
5 Correct 62 ms 22104 KB Output is correct
6 Correct 56 ms 20056 KB Output is correct
7 Correct 59 ms 20568 KB Output is correct
8 Correct 58 ms 20828 KB Output is correct
9 Correct 68 ms 21096 KB Output is correct
10 Correct 65 ms 20560 KB Output is correct
11 Correct 157 ms 30856 KB Output is correct
12 Correct 151 ms 29008 KB Output is correct
13 Correct 153 ms 29008 KB Output is correct
14 Correct 145 ms 26964 KB Output is correct
15 Correct 138 ms 25256 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 59 ms 21528 KB Output is correct
18 Correct 5 ms 860 KB Output is correct
19 Correct 3 ms 860 KB Output is correct
20 Correct 3 ms 860 KB Output is correct
21 Correct 3 ms 860 KB Output is correct
22 Correct 3 ms 860 KB Output is correct
23 Correct 3 ms 860 KB Output is correct
24 Correct 3 ms 860 KB Output is correct
25 Correct 3 ms 856 KB Output is correct
26 Correct 3 ms 856 KB Output is correct
27 Correct 4 ms 856 KB Output is correct
28 Correct 4 ms 1112 KB Output is correct
29 Correct 4 ms 1116 KB Output is correct
30 Correct 4 ms 1116 KB Output is correct
31 Correct 4 ms 860 KB Output is correct
32 Correct 4 ms 860 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 3 ms 860 KB Output is correct
35 Correct 61 ms 1608 KB Output is correct
36 Correct 56 ms 1620 KB Output is correct
37 Correct 61 ms 1872 KB Output is correct
38 Correct 59 ms 1616 KB Output is correct
39 Correct 59 ms 1620 KB Output is correct
40 Correct 60 ms 1704 KB Output is correct
41 Correct 65 ms 1620 KB Output is correct
42 Correct 62 ms 1616 KB Output is correct
43 Correct 63 ms 1616 KB Output is correct
44 Correct 67 ms 1616 KB Output is correct
45 Correct 37 ms 1368 KB Output is correct
46 Correct 37 ms 1392 KB Output is correct
47 Correct 40 ms 1448 KB Output is correct
48 Correct 38 ms 1372 KB Output is correct
49 Correct 37 ms 1372 KB Output is correct
50 Correct 0 ms 344 KB Output is correct
51 Correct 41 ms 1880 KB Output is correct
52 Correct 61 ms 22260 KB Output is correct
53 Correct 60 ms 21888 KB Output is correct
54 Correct 61 ms 20300 KB Output is correct
55 Correct 60 ms 20056 KB Output is correct
56 Correct 57 ms 20828 KB Output is correct
57 Correct 55 ms 20324 KB Output is correct
58 Correct 56 ms 20172 KB Output is correct
59 Correct 58 ms 20456 KB Output is correct
60 Correct 68 ms 20472 KB Output is correct
61 Correct 71 ms 21844 KB Output is correct
62 Correct 149 ms 28912 KB Output is correct
63 Correct 179 ms 31932 KB Output is correct
64 Correct 156 ms 28832 KB Output is correct
65 Correct 149 ms 25176 KB Output is correct
66 Correct 155 ms 27220 KB Output is correct
67 Correct 1 ms 344 KB Output is correct
68 Correct 55 ms 20996 KB Output is correct
69 Correct 224 ms 21844 KB Output is correct
70 Correct 272 ms 22976 KB Output is correct
71 Correct 345 ms 21264 KB Output is correct
72 Correct 227 ms 22352 KB Output is correct
73 Correct 279 ms 22028 KB Output is correct
74 Correct 259 ms 23172 KB Output is correct
75 Correct 220 ms 21600 KB Output is correct
76 Correct 244 ms 23380 KB Output is correct
77 Correct 270 ms 21332 KB Output is correct
78 Correct 236 ms 21932 KB Output is correct
79 Correct 217 ms 31896 KB Output is correct
80 Correct 206 ms 29524 KB Output is correct
81 Correct 200 ms 29268 KB Output is correct
82 Correct 222 ms 26036 KB Output is correct
83 Correct 198 ms 25168 KB Output is correct
84 Correct 0 ms 344 KB Output is correct
85 Correct 119 ms 21844 KB Output is correct