Submission #644005

# Submission time Handle Problem Language Result Execution time Memory
644005 2022-09-23T12:56:58 Z ymm Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
3000 ms 260880 KB
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;

const int N = 1'000'010;

struct node {
	vector<int> srt;
	int mxs;
} seg[N<<2];
int a[N];
int n;

void build(int i=0, int b=0, int e=n)
{
	if (e-b == 1) {
		seg[i].srt = {a[b]};
		seg[i].mxs = 0;
		return;
	}
	build(2*i+1, b, (b+e)/2);
	build(2*i+2, (b+e)/2, e);
	seg[i].mxs = max(seg[2*i+1].mxs, seg[2*i+2].mxs);
	auto it = lower_bound(seg[2*i+2].srt.begin(), seg[2*i+2].srt.end(), seg[2*i+1].srt.back());
	if (it != seg[2*i+2].srt.begin())
		seg[i].mxs = max(seg[i].mxs, seg[2*i+1].srt.back() + *--it);
	seg[i].srt.resize(e-b);
	merge(seg[2*i+1].srt.begin(), seg[2*i+1].srt.end(), seg[2*i+2].srt.begin(), seg[2*i+2].srt.end(), seg[i].srt.begin());
}

pii get(int l, int r, int pre=0, int i=0, int b=0, int e=n)
{
	if (l <= b && e <= r) {
		int mxs = seg[i].mxs;
		auto it = lower_bound(seg[i].srt.begin(), seg[i].srt.end(), pre);
		if (it != seg[i].srt.begin())
			mxs = max(mxs, pre + *--it);
		int mx = max(pre, seg[i].srt.back());
		return {mx, mxs};
	}
	if (r <= b || e <= l)
		return {0, 0};
	auto [pre2, ans1] = get(l, r, pre , 2*i+1, b, (b+e)/2);
	auto [pre3, ans2] = get(l, r, pre2, 2*i+2, (b+e)/2, e);
	return {pre3, max(ans1, ans2)};
}

int main()
{
	cin.tie(0) -> sync_with_stdio(false);
	int q;
	cin >> n >> q;
	Loop (i,0,n)
		cin >> a[i];
	build();
	Loop (i,0,q) {
		int l, r, k;
		cin >> l >> r >> k;
		--l;
		//int mx=0, mxs=0;
		//Loop (i,l,r) {
		//	if (a[i] >= mx)
		//		mx = a[i];
		//	else
		//		mxs = max(a[i]+mx, mxs);
		//}
		int x = get(l, r).second;
		cout << (x <= k) << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 54 ms 125540 KB Output is correct
2 Correct 55 ms 125524 KB Output is correct
3 Correct 55 ms 125516 KB Output is correct
4 Correct 54 ms 125540 KB Output is correct
5 Correct 54 ms 125576 KB Output is correct
6 Correct 55 ms 125544 KB Output is correct
7 Correct 55 ms 125564 KB Output is correct
8 Correct 55 ms 125580 KB Output is correct
9 Correct 56 ms 125552 KB Output is correct
10 Correct 54 ms 125516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 125540 KB Output is correct
2 Correct 55 ms 125524 KB Output is correct
3 Correct 55 ms 125516 KB Output is correct
4 Correct 54 ms 125540 KB Output is correct
5 Correct 54 ms 125576 KB Output is correct
6 Correct 55 ms 125544 KB Output is correct
7 Correct 55 ms 125564 KB Output is correct
8 Correct 55 ms 125580 KB Output is correct
9 Correct 56 ms 125552 KB Output is correct
10 Correct 54 ms 125516 KB Output is correct
11 Correct 57 ms 125644 KB Output is correct
12 Correct 59 ms 125952 KB Output is correct
13 Correct 66 ms 126056 KB Output is correct
14 Correct 59 ms 126028 KB Output is correct
15 Correct 62 ms 126000 KB Output is correct
16 Correct 60 ms 126016 KB Output is correct
17 Correct 60 ms 125956 KB Output is correct
18 Correct 58 ms 126080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3024 ms 260880 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 220 ms 137804 KB Output is correct
2 Correct 214 ms 138280 KB Output is correct
3 Correct 206 ms 138352 KB Output is correct
4 Correct 197 ms 138344 KB Output is correct
5 Correct 206 ms 138608 KB Output is correct
6 Correct 163 ms 138300 KB Output is correct
7 Correct 163 ms 138336 KB Output is correct
8 Correct 182 ms 138468 KB Output is correct
9 Correct 96 ms 126468 KB Output is correct
10 Correct 169 ms 138420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 125540 KB Output is correct
2 Correct 55 ms 125524 KB Output is correct
3 Correct 55 ms 125516 KB Output is correct
4 Correct 54 ms 125540 KB Output is correct
5 Correct 54 ms 125576 KB Output is correct
6 Correct 55 ms 125544 KB Output is correct
7 Correct 55 ms 125564 KB Output is correct
8 Correct 55 ms 125580 KB Output is correct
9 Correct 56 ms 125552 KB Output is correct
10 Correct 54 ms 125516 KB Output is correct
11 Correct 57 ms 125644 KB Output is correct
12 Correct 59 ms 125952 KB Output is correct
13 Correct 66 ms 126056 KB Output is correct
14 Correct 59 ms 126028 KB Output is correct
15 Correct 62 ms 126000 KB Output is correct
16 Correct 60 ms 126016 KB Output is correct
17 Correct 60 ms 125956 KB Output is correct
18 Correct 58 ms 126080 KB Output is correct
19 Correct 506 ms 151692 KB Output is correct
20 Correct 464 ms 151276 KB Output is correct
21 Correct 369 ms 151208 KB Output is correct
22 Correct 380 ms 151188 KB Output is correct
23 Correct 376 ms 151184 KB Output is correct
24 Correct 313 ms 151308 KB Output is correct
25 Correct 301 ms 151244 KB Output is correct
26 Correct 379 ms 151416 KB Output is correct
27 Correct 403 ms 151168 KB Output is correct
28 Correct 400 ms 151328 KB Output is correct
29 Correct 407 ms 151284 KB Output is correct
30 Correct 420 ms 151212 KB Output is correct
31 Correct 407 ms 151244 KB Output is correct
32 Correct 440 ms 151236 KB Output is correct
33 Correct 406 ms 151372 KB Output is correct
34 Correct 303 ms 151164 KB Output is correct
35 Correct 293 ms 151208 KB Output is correct
36 Correct 355 ms 151204 KB Output is correct
37 Correct 292 ms 151372 KB Output is correct
38 Correct 295 ms 151280 KB Output is correct
39 Correct 368 ms 151344 KB Output is correct
40 Correct 266 ms 142540 KB Output is correct
41 Correct 330 ms 151100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 125540 KB Output is correct
2 Correct 55 ms 125524 KB Output is correct
3 Correct 55 ms 125516 KB Output is correct
4 Correct 54 ms 125540 KB Output is correct
5 Correct 54 ms 125576 KB Output is correct
6 Correct 55 ms 125544 KB Output is correct
7 Correct 55 ms 125564 KB Output is correct
8 Correct 55 ms 125580 KB Output is correct
9 Correct 56 ms 125552 KB Output is correct
10 Correct 54 ms 125516 KB Output is correct
11 Correct 57 ms 125644 KB Output is correct
12 Correct 59 ms 125952 KB Output is correct
13 Correct 66 ms 126056 KB Output is correct
14 Correct 59 ms 126028 KB Output is correct
15 Correct 62 ms 126000 KB Output is correct
16 Correct 60 ms 126016 KB Output is correct
17 Correct 60 ms 125956 KB Output is correct
18 Correct 58 ms 126080 KB Output is correct
19 Execution timed out 3024 ms 260880 KB Time limit exceeded
20 Halted 0 ms 0 KB -