Submission #572105

# Submission time Handle Problem Language Result Execution time Memory
572105 2022-06-03T16:12:32 Z vovamr Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
3000 ms 250408 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#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 + 100;

ve<int> t[4 * N];
int mx[4 * N], a[N], answer[4 * N];

inline void build(int v, int vl, int vr) {
	if (vl == vr) {
		mx[v] = a[vl];
		t[v] = ve<int>(1, a[vl]);
		answer[v] = 0;
		return;
	}
	int m = vl + vr >> 1;
	build(2 * v + 1, vl, m);
	build(2 * v + 2, m + 1, vr);
	mx[v] = max(mx[2 * v + 1], mx[2 * v + 2]);
	answer[v] = max(answer[2 * v + 1], answer[2 * v + 2]);
	merge(all(t[2 * v + 1]), all(t[2 * v + 2]), back_inserter(t[v]));
	int ps = lower_bound(all(t[2 * v + 2]), mx[2 * v + 1]) - t[2 * v + 2].begin();
	if (ps != 0) { --ps; chmax(answer[v], mx[2 * v + 1] + t[2 * v + 2][ps]); }
}

inline void get(int v, int vl, int vr, int l, int r, ve<int> &pos) {
	if (l > r) return;
	else if (vl == l && vr == r) return void(pos.pb(v));
	int m = vl + vr >> 1;
	get(2 * v + 1, vl, m, l, min(r, m), pos);
	get(2 * v + 2, m + 1, vr, max(l, m + 1), r, pos);
}

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

	build(0, 0, n - 1);

	while (q--) {
		int l, r, k;
		cin >> l >> r >> k, --l, --r;

		ve<int> pos;
		get(0, 0, n - 1, l, r, pos);

		int amx = mx[pos[0]], res = answer[pos[0]];

		for (int i = 1; i < sz(pos); ++i) {
			int v = pos[i];
			int hui = lower_bound(all(t[v]), amx) - t[v].begin();

			if (hui != 0) chmax(res, amx + t[v][hui - 1]);
			chmax(res, answer[v]);
			chmax(amx, mx[v]);
		}
		cout << (k >= res ? 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;
}

Compilation message

sortbooks.cpp: In function 'void build(int, int, int)':
sortbooks.cpp:38:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |  int m = vl + vr >> 1;
      |          ~~~^~~~
sortbooks.cpp: In function 'void get(int, int, int, int, int, std::vector<int>&)':
sortbooks.cpp:51:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   51 |  int m = vl + vr >> 1;
      |          ~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 43 ms 94156 KB Output is correct
2 Correct 43 ms 94156 KB Output is correct
3 Correct 46 ms 94300 KB Output is correct
4 Correct 44 ms 94284 KB Output is correct
5 Correct 44 ms 94292 KB Output is correct
6 Correct 44 ms 94316 KB Output is correct
7 Correct 45 ms 94264 KB Output is correct
8 Correct 45 ms 94296 KB Output is correct
9 Correct 47 ms 94216 KB Output is correct
10 Correct 47 ms 94264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 94156 KB Output is correct
2 Correct 43 ms 94156 KB Output is correct
3 Correct 46 ms 94300 KB Output is correct
4 Correct 44 ms 94284 KB Output is correct
5 Correct 44 ms 94292 KB Output is correct
6 Correct 44 ms 94316 KB Output is correct
7 Correct 45 ms 94264 KB Output is correct
8 Correct 45 ms 94296 KB Output is correct
9 Correct 47 ms 94216 KB Output is correct
10 Correct 47 ms 94264 KB Output is correct
11 Correct 49 ms 94676 KB Output is correct
12 Correct 49 ms 95116 KB Output is correct
13 Correct 48 ms 95172 KB Output is correct
14 Correct 51 ms 95204 KB Output is correct
15 Correct 51 ms 95180 KB Output is correct
16 Correct 50 ms 95072 KB Output is correct
17 Correct 50 ms 94796 KB Output is correct
18 Correct 49 ms 95180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3056 ms 250408 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 243 ms 110180 KB Output is correct
2 Correct 249 ms 110232 KB Output is correct
3 Correct 220 ms 110024 KB Output is correct
4 Correct 227 ms 110028 KB Output is correct
5 Correct 221 ms 110276 KB Output is correct
6 Correct 197 ms 110128 KB Output is correct
7 Correct 195 ms 110096 KB Output is correct
8 Correct 199 ms 110272 KB Output is correct
9 Correct 93 ms 94496 KB Output is correct
10 Correct 185 ms 110096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 94156 KB Output is correct
2 Correct 43 ms 94156 KB Output is correct
3 Correct 46 ms 94300 KB Output is correct
4 Correct 44 ms 94284 KB Output is correct
5 Correct 44 ms 94292 KB Output is correct
6 Correct 44 ms 94316 KB Output is correct
7 Correct 45 ms 94264 KB Output is correct
8 Correct 45 ms 94296 KB Output is correct
9 Correct 47 ms 94216 KB Output is correct
10 Correct 47 ms 94264 KB Output is correct
11 Correct 49 ms 94676 KB Output is correct
12 Correct 49 ms 95116 KB Output is correct
13 Correct 48 ms 95172 KB Output is correct
14 Correct 51 ms 95204 KB Output is correct
15 Correct 51 ms 95180 KB Output is correct
16 Correct 50 ms 95072 KB Output is correct
17 Correct 50 ms 94796 KB Output is correct
18 Correct 49 ms 95180 KB Output is correct
19 Correct 533 ms 126812 KB Output is correct
20 Correct 514 ms 126688 KB Output is correct
21 Correct 451 ms 126856 KB Output is correct
22 Correct 454 ms 126784 KB Output is correct
23 Correct 450 ms 126672 KB Output is correct
24 Correct 416 ms 126776 KB Output is correct
25 Correct 382 ms 126748 KB Output is correct
26 Correct 461 ms 126840 KB Output is correct
27 Correct 437 ms 126696 KB Output is correct
28 Correct 452 ms 126744 KB Output is correct
29 Correct 479 ms 126656 KB Output is correct
30 Correct 454 ms 126696 KB Output is correct
31 Correct 473 ms 126860 KB Output is correct
32 Correct 473 ms 126768 KB Output is correct
33 Correct 472 ms 126660 KB Output is correct
34 Correct 394 ms 126816 KB Output is correct
35 Correct 380 ms 126780 KB Output is correct
36 Correct 374 ms 126760 KB Output is correct
37 Correct 379 ms 126668 KB Output is correct
38 Correct 385 ms 126740 KB Output is correct
39 Correct 420 ms 126760 KB Output is correct
40 Correct 283 ms 112904 KB Output is correct
41 Correct 367 ms 126748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 94156 KB Output is correct
2 Correct 43 ms 94156 KB Output is correct
3 Correct 46 ms 94300 KB Output is correct
4 Correct 44 ms 94284 KB Output is correct
5 Correct 44 ms 94292 KB Output is correct
6 Correct 44 ms 94316 KB Output is correct
7 Correct 45 ms 94264 KB Output is correct
8 Correct 45 ms 94296 KB Output is correct
9 Correct 47 ms 94216 KB Output is correct
10 Correct 47 ms 94264 KB Output is correct
11 Correct 49 ms 94676 KB Output is correct
12 Correct 49 ms 95116 KB Output is correct
13 Correct 48 ms 95172 KB Output is correct
14 Correct 51 ms 95204 KB Output is correct
15 Correct 51 ms 95180 KB Output is correct
16 Correct 50 ms 95072 KB Output is correct
17 Correct 50 ms 94796 KB Output is correct
18 Correct 49 ms 95180 KB Output is correct
19 Execution timed out 3056 ms 250408 KB Time limit exceeded
20 Halted 0 ms 0 KB -