답안 #572103

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
572103 2022-06-03T16:11:08 Z vovamr Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
64 / 100
3000 ms 256828 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[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:35:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |  int m = vl + vr >> 1;
      |          ~~~^~~~
sortbooks.cpp: In function 'void get(int, int, int, int, int, std::vector<int>&)':
sortbooks.cpp:48:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   48 |  int m = vl + vr >> 1;
      |          ~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 94164 KB Output is correct
2 Correct 43 ms 94164 KB Output is correct
3 Correct 44 ms 94284 KB Output is correct
4 Correct 46 ms 94156 KB Output is correct
5 Correct 46 ms 94172 KB Output is correct
6 Correct 46 ms 94220 KB Output is correct
7 Correct 46 ms 94236 KB Output is correct
8 Correct 46 ms 94292 KB Output is correct
9 Correct 45 ms 94284 KB Output is correct
10 Correct 48 ms 94252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 94164 KB Output is correct
2 Correct 43 ms 94164 KB Output is correct
3 Correct 44 ms 94284 KB Output is correct
4 Correct 46 ms 94156 KB Output is correct
5 Correct 46 ms 94172 KB Output is correct
6 Correct 46 ms 94220 KB Output is correct
7 Correct 46 ms 94236 KB Output is correct
8 Correct 46 ms 94292 KB Output is correct
9 Correct 45 ms 94284 KB Output is correct
10 Correct 48 ms 94252 KB Output is correct
11 Correct 49 ms 94428 KB Output is correct
12 Correct 50 ms 95172 KB Output is correct
13 Correct 49 ms 95060 KB Output is correct
14 Correct 51 ms 94968 KB Output is correct
15 Correct 58 ms 95020 KB Output is correct
16 Correct 57 ms 95048 KB Output is correct
17 Correct 54 ms 94672 KB Output is correct
18 Correct 52 ms 95004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3051 ms 256828 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 248 ms 110148 KB Output is correct
2 Correct 256 ms 110176 KB Output is correct
3 Correct 236 ms 110344 KB Output is correct
4 Correct 220 ms 110176 KB Output is correct
5 Correct 220 ms 110152 KB Output is correct
6 Correct 196 ms 110424 KB Output is correct
7 Correct 230 ms 110276 KB Output is correct
8 Correct 212 ms 110228 KB Output is correct
9 Correct 100 ms 94540 KB Output is correct
10 Correct 196 ms 110196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 94164 KB Output is correct
2 Correct 43 ms 94164 KB Output is correct
3 Correct 44 ms 94284 KB Output is correct
4 Correct 46 ms 94156 KB Output is correct
5 Correct 46 ms 94172 KB Output is correct
6 Correct 46 ms 94220 KB Output is correct
7 Correct 46 ms 94236 KB Output is correct
8 Correct 46 ms 94292 KB Output is correct
9 Correct 45 ms 94284 KB Output is correct
10 Correct 48 ms 94252 KB Output is correct
11 Correct 49 ms 94428 KB Output is correct
12 Correct 50 ms 95172 KB Output is correct
13 Correct 49 ms 95060 KB Output is correct
14 Correct 51 ms 94968 KB Output is correct
15 Correct 58 ms 95020 KB Output is correct
16 Correct 57 ms 95048 KB Output is correct
17 Correct 54 ms 94672 KB Output is correct
18 Correct 52 ms 95004 KB Output is correct
19 Correct 552 ms 127044 KB Output is correct
20 Correct 548 ms 127008 KB Output is correct
21 Correct 443 ms 127036 KB Output is correct
22 Correct 485 ms 126972 KB Output is correct
23 Correct 465 ms 127036 KB Output is correct
24 Correct 417 ms 127016 KB Output is correct
25 Correct 403 ms 127028 KB Output is correct
26 Correct 452 ms 127036 KB Output is correct
27 Correct 450 ms 127068 KB Output is correct
28 Correct 519 ms 127028 KB Output is correct
29 Correct 459 ms 127028 KB Output is correct
30 Correct 495 ms 127020 KB Output is correct
31 Correct 473 ms 127032 KB Output is correct
32 Correct 460 ms 126980 KB Output is correct
33 Correct 500 ms 127104 KB Output is correct
34 Correct 379 ms 127020 KB Output is correct
35 Correct 398 ms 126972 KB Output is correct
36 Correct 382 ms 127064 KB Output is correct
37 Correct 382 ms 127016 KB Output is correct
38 Correct 399 ms 127000 KB Output is correct
39 Correct 423 ms 126916 KB Output is correct
40 Correct 306 ms 113240 KB Output is correct
41 Correct 436 ms 127020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 94164 KB Output is correct
2 Correct 43 ms 94164 KB Output is correct
3 Correct 44 ms 94284 KB Output is correct
4 Correct 46 ms 94156 KB Output is correct
5 Correct 46 ms 94172 KB Output is correct
6 Correct 46 ms 94220 KB Output is correct
7 Correct 46 ms 94236 KB Output is correct
8 Correct 46 ms 94292 KB Output is correct
9 Correct 45 ms 94284 KB Output is correct
10 Correct 48 ms 94252 KB Output is correct
11 Correct 49 ms 94428 KB Output is correct
12 Correct 50 ms 95172 KB Output is correct
13 Correct 49 ms 95060 KB Output is correct
14 Correct 51 ms 94968 KB Output is correct
15 Correct 58 ms 95020 KB Output is correct
16 Correct 57 ms 95048 KB Output is correct
17 Correct 54 ms 94672 KB Output is correct
18 Correct 52 ms 95004 KB Output is correct
19 Execution timed out 3051 ms 256828 KB Time limit exceeded
20 Halted 0 ms 0 KB -