Submission #572119

# Submission time Handle Problem Language Result Execution time Memory
572119 2022-06-03T17:04:23 Z vovamr Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
952 ms 90104 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fi first
#define se second
#define ll long long
#define ld long double
#define sz(x) ((int)(x).size())
#define all(x) 	(x).begin(), (x).end()
#define pb push_back
#define mpp make_pair
#define ve vector
using namespace std;
using namespace __gnu_pbds;
template<class T> using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll inf = 1e18; const int iinf = 1e9;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> inline bool chmin(T& a, T b) { return (a > b ? a = b, 1 : 0); }
template <typename T> inline bool chmax(T& a, T b) { return (a < b ? a = b, 1 : 0); }

const int N = 1e6 + 10;
int a[N], f[N];
inline void upd(int i, int x) { i += 2; for (; i < N; i += i & -i) chmax(f[i], x); }
inline int get(int i) { i += 2; int ans = 0; for (; i; i -= i & -i) { chmax(ans, f[i]); } return ans; }

inline void solve() {
	int n, q;
	cin >> n >> q;
	for (int i = 0; i < n; ++i) cin >> a[i];

	ve<int> stk{0};
	ve<int> le(n, -1), re(n, -1);
	for (int i = 1; i < n; ++i) {
		while (sz(stk) && a[stk.back()] <= a[i]) stk.pop_back();
		if (sz(stk)) le[i] = stk.back();
		stk.pb(i);
	}
	stk = {n - 1};
	for (int i = n - 2; ~i; --i) {
		while (sz(stk) && a[stk.back()] >= a[i]) stk.pop_back();
		if (sz(stk)) re[i] = stk.back();
		stk.pb(i);
	}

	ve<array<int,3>> vls;
	vls.reserve(2 * n);

	for (int i = 0; i < n; ++i) {
		if (~le[i]) vls.pb({le[i], i, a[i] + a[le[i]]});
		if (~re[i]) vls.pb({i, re[i], a[i] + a[re[i]]});
	}
	
	ve<int> prv(q);
	ve<array<int,3>> qu(q);
	for (int i = 0; i < q; ++i) {
		int l, r, k;
		cin >> l >> r >> k;
		qu[i] = {--l, --r, i}, prv[i] = k;
	}

	sort(all(qu));
	sort(all(vls));

	int p = sz(vls) - 1;
	for (int i = sz(qu) - 1; ~i; --i) {
		auto &[l, r, id] = qu[i];
		while (~p && vls[p][0] >= l) { upd(vls[p][1], vls[p][2]); --p; }
		prv[id] -= get(r);
	}

	for (int i = 0; i < q; ++i) cout << (prv[i] >= 0 ? 1 : 0) << '\n';
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int q = 1; // cin >> q;
	while (q--) solve();
	cerr << fixed << setprecision(3) << "Time execution: " << (double)clock() / CLOCKS_PER_SEC << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 3 ms 600 KB Output is correct
13 Correct 4 ms 596 KB Output is correct
14 Correct 4 ms 596 KB Output is correct
15 Correct 4 ms 596 KB Output is correct
16 Correct 3 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 3 ms 612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 880 ms 57100 KB Output is correct
2 Correct 857 ms 58996 KB Output is correct
3 Correct 903 ms 58828 KB Output is correct
4 Correct 855 ms 90104 KB Output is correct
5 Correct 576 ms 36812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 5940 KB Output is correct
2 Correct 69 ms 5944 KB Output is correct
3 Correct 46 ms 3196 KB Output is correct
4 Correct 46 ms 3212 KB Output is correct
5 Correct 57 ms 3228 KB Output is correct
6 Correct 55 ms 3464 KB Output is correct
7 Correct 58 ms 3472 KB Output is correct
8 Correct 52 ms 4604 KB Output is correct
9 Correct 40 ms 2056 KB Output is correct
10 Correct 52 ms 4320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 3 ms 600 KB Output is correct
13 Correct 4 ms 596 KB Output is correct
14 Correct 4 ms 596 KB Output is correct
15 Correct 4 ms 596 KB Output is correct
16 Correct 3 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 3 ms 612 KB Output is correct
19 Correct 181 ms 11680 KB Output is correct
20 Correct 158 ms 11768 KB Output is correct
21 Correct 177 ms 11652 KB Output is correct
22 Correct 173 ms 11724 KB Output is correct
23 Correct 159 ms 11672 KB Output is correct
24 Correct 118 ms 6112 KB Output is correct
25 Correct 144 ms 6120 KB Output is correct
26 Correct 120 ms 6224 KB Output is correct
27 Correct 128 ms 6120 KB Output is correct
28 Correct 130 ms 6224 KB Output is correct
29 Correct 116 ms 6220 KB Output is correct
30 Correct 117 ms 6232 KB Output is correct
31 Correct 113 ms 6208 KB Output is correct
32 Correct 125 ms 6204 KB Output is correct
33 Correct 112 ms 6144 KB Output is correct
34 Correct 123 ms 6220 KB Output is correct
35 Correct 161 ms 6220 KB Output is correct
36 Correct 113 ms 6280 KB Output is correct
37 Correct 110 ms 6172 KB Output is correct
38 Correct 120 ms 6336 KB Output is correct
39 Correct 120 ms 8140 KB Output is correct
40 Correct 102 ms 6688 KB Output is correct
41 Correct 141 ms 8336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 3 ms 600 KB Output is correct
13 Correct 4 ms 596 KB Output is correct
14 Correct 4 ms 596 KB Output is correct
15 Correct 4 ms 596 KB Output is correct
16 Correct 3 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 3 ms 612 KB Output is correct
19 Correct 880 ms 57100 KB Output is correct
20 Correct 857 ms 58996 KB Output is correct
21 Correct 903 ms 58828 KB Output is correct
22 Correct 855 ms 90104 KB Output is correct
23 Correct 576 ms 36812 KB Output is correct
24 Correct 81 ms 5940 KB Output is correct
25 Correct 69 ms 5944 KB Output is correct
26 Correct 46 ms 3196 KB Output is correct
27 Correct 46 ms 3212 KB Output is correct
28 Correct 57 ms 3228 KB Output is correct
29 Correct 55 ms 3464 KB Output is correct
30 Correct 58 ms 3472 KB Output is correct
31 Correct 52 ms 4604 KB Output is correct
32 Correct 40 ms 2056 KB Output is correct
33 Correct 52 ms 4320 KB Output is correct
34 Correct 181 ms 11680 KB Output is correct
35 Correct 158 ms 11768 KB Output is correct
36 Correct 177 ms 11652 KB Output is correct
37 Correct 173 ms 11724 KB Output is correct
38 Correct 159 ms 11672 KB Output is correct
39 Correct 118 ms 6112 KB Output is correct
40 Correct 144 ms 6120 KB Output is correct
41 Correct 120 ms 6224 KB Output is correct
42 Correct 128 ms 6120 KB Output is correct
43 Correct 130 ms 6224 KB Output is correct
44 Correct 116 ms 6220 KB Output is correct
45 Correct 117 ms 6232 KB Output is correct
46 Correct 113 ms 6208 KB Output is correct
47 Correct 125 ms 6204 KB Output is correct
48 Correct 112 ms 6144 KB Output is correct
49 Correct 123 ms 6220 KB Output is correct
50 Correct 161 ms 6220 KB Output is correct
51 Correct 113 ms 6280 KB Output is correct
52 Correct 110 ms 6172 KB Output is correct
53 Correct 120 ms 6336 KB Output is correct
54 Correct 120 ms 8140 KB Output is correct
55 Correct 102 ms 6688 KB Output is correct
56 Correct 141 ms 8336 KB Output is correct
57 Correct 952 ms 79112 KB Output is correct
58 Correct 857 ms 64392 KB Output is correct
59 Correct 856 ms 64100 KB Output is correct
60 Correct 855 ms 64544 KB Output is correct
61 Correct 868 ms 64184 KB Output is correct
62 Correct 843 ms 64292 KB Output is correct
63 Correct 648 ms 36688 KB Output is correct
64 Correct 651 ms 36756 KB Output is correct
65 Correct 626 ms 36760 KB Output is correct
66 Correct 658 ms 58024 KB Output is correct
67 Correct 661 ms 58040 KB Output is correct
68 Correct 616 ms 36624 KB Output is correct
69 Correct 602 ms 36576 KB Output is correct
70 Correct 666 ms 58404 KB Output is correct
71 Correct 616 ms 58060 KB Output is correct
72 Correct 601 ms 36456 KB Output is correct
73 Correct 636 ms 36576 KB Output is correct
74 Correct 645 ms 36360 KB Output is correct
75 Correct 628 ms 36260 KB Output is correct
76 Correct 648 ms 36244 KB Output is correct
77 Correct 633 ms 36176 KB Output is correct
78 Correct 655 ms 45316 KB Output is correct
79 Correct 562 ms 35964 KB Output is correct
80 Correct 650 ms 48508 KB Output is correct