Submission #572102

# Submission time Handle Problem Language Result Execution time Memory
572102 2022-06-03T16:07:20 Z vovamr Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
534 ms 203252 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 + 100;

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

inline void build(int v, int vl, int vr) {
	if (vl == vr) {
		mx[v] = a[vl];
		t[v] = ve<int>(1, a[vl]);
		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:34:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   34 |  int m = vl + vr >> 1;
      |          ~~~^~~~
sortbooks.cpp: In function 'void get(int, int, int, int, int, std::vector<int>&)':
sortbooks.cpp:47:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   47 |  int m = vl + vr >> 1;
      |          ~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 45 ms 94156 KB Output is correct
2 Correct 49 ms 94176 KB Output is correct
3 Correct 44 ms 94304 KB Output is correct
4 Correct 45 ms 94260 KB Output is correct
5 Correct 44 ms 94284 KB Output is correct
6 Correct 45 ms 94268 KB Output is correct
7 Correct 47 ms 94292 KB Output is correct
8 Correct 45 ms 94284 KB Output is correct
9 Correct 47 ms 94236 KB Output is correct
10 Correct 46 ms 94248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 94156 KB Output is correct
2 Correct 49 ms 94176 KB Output is correct
3 Correct 44 ms 94304 KB Output is correct
4 Correct 45 ms 94260 KB Output is correct
5 Correct 44 ms 94284 KB Output is correct
6 Correct 45 ms 94268 KB Output is correct
7 Correct 47 ms 94292 KB Output is correct
8 Correct 45 ms 94284 KB Output is correct
9 Correct 47 ms 94236 KB Output is correct
10 Correct 46 ms 94248 KB Output is correct
11 Correct 48 ms 94456 KB Output is correct
12 Correct 52 ms 95096 KB Output is correct
13 Correct 56 ms 95044 KB Output is correct
14 Correct 58 ms 95116 KB Output is correct
15 Correct 56 ms 95192 KB Output is correct
16 Correct 51 ms 95052 KB Output is correct
17 Correct 49 ms 94796 KB Output is correct
18 Correct 54 ms 95128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 233 ms 203252 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 265 ms 111568 KB Output is correct
2 Correct 244 ms 111492 KB Output is correct
3 Correct 235 ms 111556 KB Output is correct
4 Correct 244 ms 111588 KB Output is correct
5 Correct 217 ms 111720 KB Output is correct
6 Correct 196 ms 111412 KB Output is correct
7 Correct 206 ms 111540 KB Output is correct
8 Correct 187 ms 111324 KB Output is correct
9 Correct 95 ms 95820 KB Output is correct
10 Correct 204 ms 111408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 94156 KB Output is correct
2 Correct 49 ms 94176 KB Output is correct
3 Correct 44 ms 94304 KB Output is correct
4 Correct 45 ms 94260 KB Output is correct
5 Correct 44 ms 94284 KB Output is correct
6 Correct 45 ms 94268 KB Output is correct
7 Correct 47 ms 94292 KB Output is correct
8 Correct 45 ms 94284 KB Output is correct
9 Correct 47 ms 94236 KB Output is correct
10 Correct 46 ms 94248 KB Output is correct
11 Correct 48 ms 94456 KB Output is correct
12 Correct 52 ms 95096 KB Output is correct
13 Correct 56 ms 95044 KB Output is correct
14 Correct 58 ms 95116 KB Output is correct
15 Correct 56 ms 95192 KB Output is correct
16 Correct 51 ms 95052 KB Output is correct
17 Correct 49 ms 94796 KB Output is correct
18 Correct 54 ms 95128 KB Output is correct
19 Correct 534 ms 130616 KB Output is correct
20 Correct 533 ms 130568 KB Output is correct
21 Correct 490 ms 130612 KB Output is correct
22 Correct 475 ms 130532 KB Output is correct
23 Correct 463 ms 130572 KB Output is correct
24 Correct 414 ms 130612 KB Output is correct
25 Correct 392 ms 130496 KB Output is correct
26 Correct 459 ms 130748 KB Output is correct
27 Correct 456 ms 130612 KB Output is correct
28 Correct 468 ms 130640 KB Output is correct
29 Correct 472 ms 130716 KB Output is correct
30 Correct 463 ms 130820 KB Output is correct
31 Correct 475 ms 130756 KB Output is correct
32 Correct 478 ms 130752 KB Output is correct
33 Correct 474 ms 130744 KB Output is correct
34 Correct 396 ms 130444 KB Output is correct
35 Correct 392 ms 130372 KB Output is correct
36 Correct 395 ms 130184 KB Output is correct
37 Correct 398 ms 130216 KB Output is correct
38 Correct 394 ms 130360 KB Output is correct
39 Correct 431 ms 129372 KB Output is correct
40 Correct 289 ms 115280 KB Output is correct
41 Correct 398 ms 128900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 94156 KB Output is correct
2 Correct 49 ms 94176 KB Output is correct
3 Correct 44 ms 94304 KB Output is correct
4 Correct 45 ms 94260 KB Output is correct
5 Correct 44 ms 94284 KB Output is correct
6 Correct 45 ms 94268 KB Output is correct
7 Correct 47 ms 94292 KB Output is correct
8 Correct 45 ms 94284 KB Output is correct
9 Correct 47 ms 94236 KB Output is correct
10 Correct 46 ms 94248 KB Output is correct
11 Correct 48 ms 94456 KB Output is correct
12 Correct 52 ms 95096 KB Output is correct
13 Correct 56 ms 95044 KB Output is correct
14 Correct 58 ms 95116 KB Output is correct
15 Correct 56 ms 95192 KB Output is correct
16 Correct 51 ms 95052 KB Output is correct
17 Correct 49 ms 94796 KB Output is correct
18 Correct 54 ms 95128 KB Output is correct
19 Runtime error 233 ms 203252 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -