#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<ll> srt;
ll mxs;
} seg[N<<2];
ll 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());
}
pll get(int l, int r, ll pre=0, int i=0, int b=0, int e=n)
{
if (l <= b && e <= r) {
ll 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);
ll 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;
ll 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';
}
}
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:64:6: warning: unused variable 'mx' [-Wunused-variable]
64 | ll mx=0, mxs=0;
| ^~
sortbooks.cpp:64:12: warning: unused variable 'mxs' [-Wunused-variable]
64 | ll mx=0, mxs=0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
125496 KB |
Output is correct |
2 |
Correct |
57 ms |
125552 KB |
Output is correct |
3 |
Correct |
56 ms |
125456 KB |
Output is correct |
4 |
Correct |
57 ms |
125476 KB |
Output is correct |
5 |
Correct |
87 ms |
125508 KB |
Output is correct |
6 |
Correct |
56 ms |
125568 KB |
Output is correct |
7 |
Correct |
62 ms |
125640 KB |
Output is correct |
8 |
Correct |
57 ms |
125580 KB |
Output is correct |
9 |
Correct |
55 ms |
125516 KB |
Output is correct |
10 |
Correct |
56 ms |
125564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
125496 KB |
Output is correct |
2 |
Correct |
57 ms |
125552 KB |
Output is correct |
3 |
Correct |
56 ms |
125456 KB |
Output is correct |
4 |
Correct |
57 ms |
125476 KB |
Output is correct |
5 |
Correct |
87 ms |
125508 KB |
Output is correct |
6 |
Correct |
56 ms |
125568 KB |
Output is correct |
7 |
Correct |
62 ms |
125640 KB |
Output is correct |
8 |
Correct |
57 ms |
125580 KB |
Output is correct |
9 |
Correct |
55 ms |
125516 KB |
Output is correct |
10 |
Correct |
56 ms |
125564 KB |
Output is correct |
11 |
Correct |
62 ms |
125764 KB |
Output is correct |
12 |
Correct |
65 ms |
126352 KB |
Output is correct |
13 |
Correct |
60 ms |
126336 KB |
Output is correct |
14 |
Correct |
69 ms |
126448 KB |
Output is correct |
15 |
Correct |
63 ms |
126392 KB |
Output is correct |
16 |
Correct |
62 ms |
126412 KB |
Output is correct |
17 |
Correct |
61 ms |
126228 KB |
Output is correct |
18 |
Correct |
62 ms |
126288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
309 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
236 ms |
144144 KB |
Output is correct |
2 |
Correct |
231 ms |
145080 KB |
Output is correct |
3 |
Correct |
257 ms |
146060 KB |
Output is correct |
4 |
Correct |
206 ms |
145972 KB |
Output is correct |
5 |
Correct |
251 ms |
145932 KB |
Output is correct |
6 |
Correct |
171 ms |
145820 KB |
Output is correct |
7 |
Correct |
174 ms |
145768 KB |
Output is correct |
8 |
Correct |
191 ms |
145696 KB |
Output is correct |
9 |
Correct |
98 ms |
127116 KB |
Output is correct |
10 |
Correct |
179 ms |
145612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
125496 KB |
Output is correct |
2 |
Correct |
57 ms |
125552 KB |
Output is correct |
3 |
Correct |
56 ms |
125456 KB |
Output is correct |
4 |
Correct |
57 ms |
125476 KB |
Output is correct |
5 |
Correct |
87 ms |
125508 KB |
Output is correct |
6 |
Correct |
56 ms |
125568 KB |
Output is correct |
7 |
Correct |
62 ms |
125640 KB |
Output is correct |
8 |
Correct |
57 ms |
125580 KB |
Output is correct |
9 |
Correct |
55 ms |
125516 KB |
Output is correct |
10 |
Correct |
56 ms |
125564 KB |
Output is correct |
11 |
Correct |
62 ms |
125764 KB |
Output is correct |
12 |
Correct |
65 ms |
126352 KB |
Output is correct |
13 |
Correct |
60 ms |
126336 KB |
Output is correct |
14 |
Correct |
69 ms |
126448 KB |
Output is correct |
15 |
Correct |
63 ms |
126392 KB |
Output is correct |
16 |
Correct |
62 ms |
126412 KB |
Output is correct |
17 |
Correct |
61 ms |
126228 KB |
Output is correct |
18 |
Correct |
62 ms |
126288 KB |
Output is correct |
19 |
Correct |
502 ms |
167236 KB |
Output is correct |
20 |
Correct |
497 ms |
170512 KB |
Output is correct |
21 |
Correct |
480 ms |
170444 KB |
Output is correct |
22 |
Correct |
418 ms |
170524 KB |
Output is correct |
23 |
Correct |
390 ms |
170456 KB |
Output is correct |
24 |
Correct |
339 ms |
170276 KB |
Output is correct |
25 |
Correct |
352 ms |
170244 KB |
Output is correct |
26 |
Correct |
457 ms |
170472 KB |
Output is correct |
27 |
Correct |
412 ms |
170528 KB |
Output is correct |
28 |
Correct |
461 ms |
170528 KB |
Output is correct |
29 |
Correct |
442 ms |
170508 KB |
Output is correct |
30 |
Correct |
437 ms |
170524 KB |
Output is correct |
31 |
Correct |
481 ms |
170612 KB |
Output is correct |
32 |
Correct |
453 ms |
170484 KB |
Output is correct |
33 |
Correct |
466 ms |
170536 KB |
Output is correct |
34 |
Correct |
332 ms |
170304 KB |
Output is correct |
35 |
Correct |
327 ms |
170232 KB |
Output is correct |
36 |
Correct |
317 ms |
169960 KB |
Output is correct |
37 |
Correct |
332 ms |
169992 KB |
Output is correct |
38 |
Correct |
360 ms |
170188 KB |
Output is correct |
39 |
Correct |
380 ms |
169172 KB |
Output is correct |
40 |
Correct |
285 ms |
155008 KB |
Output is correct |
41 |
Correct |
354 ms |
168652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
125496 KB |
Output is correct |
2 |
Correct |
57 ms |
125552 KB |
Output is correct |
3 |
Correct |
56 ms |
125456 KB |
Output is correct |
4 |
Correct |
57 ms |
125476 KB |
Output is correct |
5 |
Correct |
87 ms |
125508 KB |
Output is correct |
6 |
Correct |
56 ms |
125568 KB |
Output is correct |
7 |
Correct |
62 ms |
125640 KB |
Output is correct |
8 |
Correct |
57 ms |
125580 KB |
Output is correct |
9 |
Correct |
55 ms |
125516 KB |
Output is correct |
10 |
Correct |
56 ms |
125564 KB |
Output is correct |
11 |
Correct |
62 ms |
125764 KB |
Output is correct |
12 |
Correct |
65 ms |
126352 KB |
Output is correct |
13 |
Correct |
60 ms |
126336 KB |
Output is correct |
14 |
Correct |
69 ms |
126448 KB |
Output is correct |
15 |
Correct |
63 ms |
126392 KB |
Output is correct |
16 |
Correct |
62 ms |
126412 KB |
Output is correct |
17 |
Correct |
61 ms |
126228 KB |
Output is correct |
18 |
Correct |
62 ms |
126288 KB |
Output is correct |
19 |
Runtime error |
309 ms |
262144 KB |
Execution killed with signal 9 |
20 |
Halted |
0 ms |
0 KB |
- |