Submission #530846

# Submission time Handle Problem Language Result Execution time Memory
530846 2022-02-27T01:26:33 Z abc864197532 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1065 ms 155048 KB
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define pii pair<int,int>
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T i, U ...j) {
	cout << i << ' ', abc(j...);
}
template <typename T> void printv(T l, T r) {
	for (; l != r; ++l)
		cout << *l << " \n"[l + 1 == r];
}
#ifdef Doludu
#define test(x...) abc("[" + string(#x) + "]", x);
#define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#else
#define test(x...) void(0)
#define owo ios::sync_with_stdio(false)
#endif
const int N = 1e6 + 87;

int bit[N];

void add(int p, int v) {
	for (; p > 0; p -= p & (-p))
		bit[p] = max(bit[p], v);
}

int query(int p) {
	int ans = 0;
	for (; p < N; p += p & (-p))
		ans = max(ans, bit[p]);
	return ans;
}

vector <int> seg[N], queries[N];

int l[N], r[N], k[N];

int main () {
	owo;
	int n, q;
	cin >> n >> q;
	vector <int> a(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	vector <int> stk;
	for (int i = 0; i < n; ++i) {
		while (!stk.empty() && a[stk.back()] <= a[i])
			stk.pop_back();
		if (!stk.empty()) {
			seg[i].pb(stk.back());
		}
		stk.pb(i);
	}
	stk.clear();
	for (int i = n - 1; ~i; --i) {
		while (!stk.empty() && a[stk.back()] >= a[i])
			stk.pop_back();
		if (!stk.empty()) {
			seg[stk.back()].pb(i);
		}
		stk.pb(i);
	}
	for (int i = 0; i < q; ++i)
		cin >> l[i] >> r[i] >> k[i], --l[i], --r[i], queries[r[i]].pb(i);
	vector <int> ans(q);
	for (int i = 0; i < n; ++i) {
		for (int j : seg[i]) {
			add(j + 2, a[i] + a[j]);
		}
		for (int id : queries[i]) {
			ans[id] = query(l[id] + 2);
		}
	}
	for (int i = 0; i < q; ++i)
		cout << (ans[i] <= k[i] ? 1 : 0) << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 24 ms 47456 KB Output is correct
2 Correct 21 ms 47216 KB Output is correct
3 Correct 22 ms 47264 KB Output is correct
4 Correct 22 ms 47292 KB Output is correct
5 Correct 27 ms 47232 KB Output is correct
6 Correct 23 ms 47236 KB Output is correct
7 Correct 21 ms 47320 KB Output is correct
8 Correct 22 ms 47232 KB Output is correct
9 Correct 22 ms 47308 KB Output is correct
10 Correct 21 ms 47308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 47456 KB Output is correct
2 Correct 21 ms 47216 KB Output is correct
3 Correct 22 ms 47264 KB Output is correct
4 Correct 22 ms 47292 KB Output is correct
5 Correct 27 ms 47232 KB Output is correct
6 Correct 23 ms 47236 KB Output is correct
7 Correct 21 ms 47320 KB Output is correct
8 Correct 22 ms 47232 KB Output is correct
9 Correct 22 ms 47308 KB Output is correct
10 Correct 21 ms 47308 KB Output is correct
11 Correct 23 ms 47436 KB Output is correct
12 Correct 24 ms 47688 KB Output is correct
13 Correct 24 ms 47628 KB Output is correct
14 Correct 26 ms 47840 KB Output is correct
15 Correct 26 ms 47824 KB Output is correct
16 Correct 25 ms 47564 KB Output is correct
17 Correct 25 ms 47596 KB Output is correct
18 Correct 25 ms 47688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1031 ms 123188 KB Output is correct
2 Correct 1012 ms 123344 KB Output is correct
3 Correct 1026 ms 123348 KB Output is correct
4 Correct 1056 ms 123268 KB Output is correct
5 Correct 825 ms 86988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 88 ms 56652 KB Output is correct
2 Correct 83 ms 55948 KB Output is correct
3 Correct 71 ms 52748 KB Output is correct
4 Correct 72 ms 52980 KB Output is correct
5 Correct 83 ms 53016 KB Output is correct
6 Correct 69 ms 52164 KB Output is correct
7 Correct 65 ms 52132 KB Output is correct
8 Correct 77 ms 54976 KB Output is correct
9 Correct 71 ms 49600 KB Output is correct
10 Correct 75 ms 54588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 47456 KB Output is correct
2 Correct 21 ms 47216 KB Output is correct
3 Correct 22 ms 47264 KB Output is correct
4 Correct 22 ms 47292 KB Output is correct
5 Correct 27 ms 47232 KB Output is correct
6 Correct 23 ms 47236 KB Output is correct
7 Correct 21 ms 47320 KB Output is correct
8 Correct 22 ms 47232 KB Output is correct
9 Correct 22 ms 47308 KB Output is correct
10 Correct 21 ms 47308 KB Output is correct
11 Correct 23 ms 47436 KB Output is correct
12 Correct 24 ms 47688 KB Output is correct
13 Correct 24 ms 47628 KB Output is correct
14 Correct 26 ms 47840 KB Output is correct
15 Correct 26 ms 47824 KB Output is correct
16 Correct 25 ms 47564 KB Output is correct
17 Correct 25 ms 47596 KB Output is correct
18 Correct 25 ms 47688 KB Output is correct
19 Correct 203 ms 68728 KB Output is correct
20 Correct 185 ms 68672 KB Output is correct
21 Correct 164 ms 66884 KB Output is correct
22 Correct 170 ms 66856 KB Output is correct
23 Correct 157 ms 67012 KB Output is correct
24 Correct 136 ms 59296 KB Output is correct
25 Correct 141 ms 59332 KB Output is correct
26 Correct 146 ms 60228 KB Output is correct
27 Correct 141 ms 60236 KB Output is correct
28 Correct 144 ms 60484 KB Output is correct
29 Correct 157 ms 61384 KB Output is correct
30 Correct 173 ms 61388 KB Output is correct
31 Correct 158 ms 61288 KB Output is correct
32 Correct 162 ms 61380 KB Output is correct
33 Correct 156 ms 61392 KB Output is correct
34 Correct 146 ms 58960 KB Output is correct
35 Correct 135 ms 58896 KB Output is correct
36 Correct 143 ms 58832 KB Output is correct
37 Correct 125 ms 58820 KB Output is correct
38 Correct 146 ms 58960 KB Output is correct
39 Correct 165 ms 62000 KB Output is correct
40 Correct 135 ms 59980 KB Output is correct
41 Correct 163 ms 63152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 47456 KB Output is correct
2 Correct 21 ms 47216 KB Output is correct
3 Correct 22 ms 47264 KB Output is correct
4 Correct 22 ms 47292 KB Output is correct
5 Correct 27 ms 47232 KB Output is correct
6 Correct 23 ms 47236 KB Output is correct
7 Correct 21 ms 47320 KB Output is correct
8 Correct 22 ms 47232 KB Output is correct
9 Correct 22 ms 47308 KB Output is correct
10 Correct 21 ms 47308 KB Output is correct
11 Correct 23 ms 47436 KB Output is correct
12 Correct 24 ms 47688 KB Output is correct
13 Correct 24 ms 47628 KB Output is correct
14 Correct 26 ms 47840 KB Output is correct
15 Correct 26 ms 47824 KB Output is correct
16 Correct 25 ms 47564 KB Output is correct
17 Correct 25 ms 47596 KB Output is correct
18 Correct 25 ms 47688 KB Output is correct
19 Correct 1031 ms 123188 KB Output is correct
20 Correct 1012 ms 123344 KB Output is correct
21 Correct 1026 ms 123348 KB Output is correct
22 Correct 1056 ms 123268 KB Output is correct
23 Correct 825 ms 86988 KB Output is correct
24 Correct 88 ms 56652 KB Output is correct
25 Correct 83 ms 55948 KB Output is correct
26 Correct 71 ms 52748 KB Output is correct
27 Correct 72 ms 52980 KB Output is correct
28 Correct 83 ms 53016 KB Output is correct
29 Correct 69 ms 52164 KB Output is correct
30 Correct 65 ms 52132 KB Output is correct
31 Correct 77 ms 54976 KB Output is correct
32 Correct 71 ms 49600 KB Output is correct
33 Correct 75 ms 54588 KB Output is correct
34 Correct 203 ms 68728 KB Output is correct
35 Correct 185 ms 68672 KB Output is correct
36 Correct 164 ms 66884 KB Output is correct
37 Correct 170 ms 66856 KB Output is correct
38 Correct 157 ms 67012 KB Output is correct
39 Correct 136 ms 59296 KB Output is correct
40 Correct 141 ms 59332 KB Output is correct
41 Correct 146 ms 60228 KB Output is correct
42 Correct 141 ms 60236 KB Output is correct
43 Correct 144 ms 60484 KB Output is correct
44 Correct 157 ms 61384 KB Output is correct
45 Correct 173 ms 61388 KB Output is correct
46 Correct 158 ms 61288 KB Output is correct
47 Correct 162 ms 61380 KB Output is correct
48 Correct 156 ms 61392 KB Output is correct
49 Correct 146 ms 58960 KB Output is correct
50 Correct 135 ms 58896 KB Output is correct
51 Correct 143 ms 58832 KB Output is correct
52 Correct 125 ms 58820 KB Output is correct
53 Correct 146 ms 58960 KB Output is correct
54 Correct 165 ms 62000 KB Output is correct
55 Correct 135 ms 59980 KB Output is correct
56 Correct 163 ms 63152 KB Output is correct
57 Correct 1065 ms 155048 KB Output is correct
58 Correct 1006 ms 155016 KB Output is correct
59 Correct 934 ms 150716 KB Output is correct
60 Correct 958 ms 150740 KB Output is correct
61 Correct 938 ms 150724 KB Output is correct
62 Correct 961 ms 150828 KB Output is correct
63 Correct 553 ms 106960 KB Output is correct
64 Correct 588 ms 106724 KB Output is correct
65 Correct 764 ms 113880 KB Output is correct
66 Correct 781 ms 113840 KB Output is correct
67 Correct 791 ms 114176 KB Output is correct
68 Correct 829 ms 118672 KB Output is correct
69 Correct 847 ms 118452 KB Output is correct
70 Correct 852 ms 117896 KB Output is correct
71 Correct 824 ms 117788 KB Output is correct
72 Correct 833 ms 117684 KB Output is correct
73 Correct 527 ms 104676 KB Output is correct
74 Correct 557 ms 105584 KB Output is correct
75 Correct 530 ms 104644 KB Output is correct
76 Correct 527 ms 104780 KB Output is correct
77 Correct 546 ms 104608 KB Output is correct
78 Correct 785 ms 122616 KB Output is correct
79 Correct 615 ms 107724 KB Output is correct
80 Correct 764 ms 131776 KB Output is correct