Submission #930343

# Submission time Handle Problem Language Result Execution time Memory
930343 2024-02-19T12:14:02 Z NK_ Osumnjičeni (COCI21_osumnjiceni) C++17
110 / 110
634 ms 39112 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++) A[i] = mp(L[i], R[i]);
	
	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);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:24:6: warning: variable 'M' set but not used [-Wunused-but-set-variable]
   24 |  int M = -1;
      |      ^
# Verdict Execution time Memory Grader output
1 Correct 371 ms 26380 KB Output is correct
2 Correct 364 ms 26192 KB Output is correct
3 Correct 436 ms 26040 KB Output is correct
4 Correct 386 ms 26448 KB Output is correct
5 Correct 397 ms 27652 KB Output is correct
6 Correct 60 ms 25168 KB Output is correct
7 Correct 66 ms 25668 KB Output is correct
8 Correct 67 ms 25680 KB Output is correct
9 Correct 75 ms 26452 KB Output is correct
10 Correct 82 ms 25564 KB Output is correct
11 Correct 466 ms 36180 KB Output is correct
12 Correct 424 ms 33404 KB Output is correct
13 Correct 450 ms 33564 KB Output is correct
14 Correct 413 ms 31764 KB Output is correct
15 Correct 409 ms 29888 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 63 ms 26936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1200 KB Output is correct
2 Correct 6 ms 1112 KB Output is correct
3 Correct 6 ms 1116 KB Output is correct
4 Correct 6 ms 1112 KB Output is correct
5 Correct 6 ms 1108 KB Output is correct
6 Correct 4 ms 1316 KB Output is correct
7 Correct 3 ms 1116 KB Output is correct
8 Correct 3 ms 1152 KB Output is correct
9 Correct 3 ms 1112 KB Output is correct
10 Correct 3 ms 1116 KB Output is correct
11 Correct 6 ms 1372 KB Output is correct
12 Correct 6 ms 1116 KB Output is correct
13 Correct 6 ms 1116 KB Output is correct
14 Correct 6 ms 1056 KB Output is correct
15 Correct 6 ms 1116 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 3 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1200 KB Output is correct
2 Correct 6 ms 1112 KB Output is correct
3 Correct 6 ms 1116 KB Output is correct
4 Correct 6 ms 1112 KB Output is correct
5 Correct 6 ms 1108 KB Output is correct
6 Correct 4 ms 1316 KB Output is correct
7 Correct 3 ms 1116 KB Output is correct
8 Correct 3 ms 1152 KB Output is correct
9 Correct 3 ms 1112 KB Output is correct
10 Correct 3 ms 1116 KB Output is correct
11 Correct 6 ms 1372 KB Output is correct
12 Correct 6 ms 1116 KB Output is correct
13 Correct 6 ms 1116 KB Output is correct
14 Correct 6 ms 1056 KB Output is correct
15 Correct 6 ms 1116 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 3 ms 1116 KB Output is correct
18 Correct 63 ms 3664 KB Output is correct
19 Correct 59 ms 3464 KB Output is correct
20 Correct 67 ms 3664 KB Output is correct
21 Correct 64 ms 3408 KB Output is correct
22 Correct 60 ms 3664 KB Output is correct
23 Correct 56 ms 3416 KB Output is correct
24 Correct 75 ms 3588 KB Output is correct
25 Correct 63 ms 3664 KB Output is correct
26 Correct 56 ms 3608 KB Output is correct
27 Correct 52 ms 3408 KB Output is correct
28 Correct 41 ms 3156 KB Output is correct
29 Correct 40 ms 3356 KB Output is correct
30 Correct 47 ms 3408 KB Output is correct
31 Correct 41 ms 3156 KB Output is correct
32 Correct 40 ms 3152 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 42 ms 3296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 459 ms 27712 KB Output is correct
2 Correct 368 ms 27216 KB Output is correct
3 Correct 375 ms 25256 KB Output is correct
4 Correct 381 ms 24916 KB Output is correct
5 Correct 349 ms 25684 KB Output is correct
6 Correct 58 ms 25460 KB Output is correct
7 Correct 62 ms 25172 KB Output is correct
8 Correct 70 ms 25288 KB Output is correct
9 Correct 70 ms 25016 KB Output is correct
10 Correct 84 ms 26964 KB Output is correct
11 Correct 460 ms 33240 KB Output is correct
12 Correct 446 ms 36424 KB Output is correct
13 Correct 404 ms 33360 KB Output is correct
14 Correct 458 ms 29804 KB Output is correct
15 Correct 497 ms 32204 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 57 ms 25692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 371 ms 26380 KB Output is correct
2 Correct 364 ms 26192 KB Output is correct
3 Correct 436 ms 26040 KB Output is correct
4 Correct 386 ms 26448 KB Output is correct
5 Correct 397 ms 27652 KB Output is correct
6 Correct 60 ms 25168 KB Output is correct
7 Correct 66 ms 25668 KB Output is correct
8 Correct 67 ms 25680 KB Output is correct
9 Correct 75 ms 26452 KB Output is correct
10 Correct 82 ms 25564 KB Output is correct
11 Correct 466 ms 36180 KB Output is correct
12 Correct 424 ms 33404 KB Output is correct
13 Correct 450 ms 33564 KB Output is correct
14 Correct 413 ms 31764 KB Output is correct
15 Correct 409 ms 29888 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 63 ms 26936 KB Output is correct
18 Correct 6 ms 1200 KB Output is correct
19 Correct 6 ms 1112 KB Output is correct
20 Correct 6 ms 1116 KB Output is correct
21 Correct 6 ms 1112 KB Output is correct
22 Correct 6 ms 1108 KB Output is correct
23 Correct 4 ms 1316 KB Output is correct
24 Correct 3 ms 1116 KB Output is correct
25 Correct 3 ms 1152 KB Output is correct
26 Correct 3 ms 1112 KB Output is correct
27 Correct 3 ms 1116 KB Output is correct
28 Correct 6 ms 1372 KB Output is correct
29 Correct 6 ms 1116 KB Output is correct
30 Correct 6 ms 1116 KB Output is correct
31 Correct 6 ms 1056 KB Output is correct
32 Correct 6 ms 1116 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 3 ms 1116 KB Output is correct
35 Correct 63 ms 3664 KB Output is correct
36 Correct 59 ms 3464 KB Output is correct
37 Correct 67 ms 3664 KB Output is correct
38 Correct 64 ms 3408 KB Output is correct
39 Correct 60 ms 3664 KB Output is correct
40 Correct 56 ms 3416 KB Output is correct
41 Correct 75 ms 3588 KB Output is correct
42 Correct 63 ms 3664 KB Output is correct
43 Correct 56 ms 3608 KB Output is correct
44 Correct 52 ms 3408 KB Output is correct
45 Correct 41 ms 3156 KB Output is correct
46 Correct 40 ms 3356 KB Output is correct
47 Correct 47 ms 3408 KB Output is correct
48 Correct 41 ms 3156 KB Output is correct
49 Correct 40 ms 3152 KB Output is correct
50 Correct 0 ms 344 KB Output is correct
51 Correct 42 ms 3296 KB Output is correct
52 Correct 459 ms 27712 KB Output is correct
53 Correct 368 ms 27216 KB Output is correct
54 Correct 375 ms 25256 KB Output is correct
55 Correct 381 ms 24916 KB Output is correct
56 Correct 349 ms 25684 KB Output is correct
57 Correct 58 ms 25460 KB Output is correct
58 Correct 62 ms 25172 KB Output is correct
59 Correct 70 ms 25288 KB Output is correct
60 Correct 70 ms 25016 KB Output is correct
61 Correct 84 ms 26964 KB Output is correct
62 Correct 460 ms 33240 KB Output is correct
63 Correct 446 ms 36424 KB Output is correct
64 Correct 404 ms 33360 KB Output is correct
65 Correct 458 ms 29804 KB Output is correct
66 Correct 497 ms 32204 KB Output is correct
67 Correct 0 ms 348 KB Output is correct
68 Correct 57 ms 25692 KB Output is correct
69 Correct 582 ms 29200 KB Output is correct
70 Correct 634 ms 30820 KB Output is correct
71 Correct 546 ms 28416 KB Output is correct
72 Correct 525 ms 29776 KB Output is correct
73 Correct 532 ms 29380 KB Output is correct
74 Correct 256 ms 31052 KB Output is correct
75 Correct 236 ms 29008 KB Output is correct
76 Correct 234 ms 31056 KB Output is correct
77 Correct 241 ms 28756 KB Output is correct
78 Correct 224 ms 29128 KB Output is correct
79 Correct 548 ms 39112 KB Output is correct
80 Correct 517 ms 36244 KB Output is correct
81 Correct 440 ms 36000 KB Output is correct
82 Correct 453 ms 33096 KB Output is correct
83 Correct 443 ms 31936 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 126 ms 29248 KB Output is correct