#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 = 200'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, *--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;
int x = get(l, r).second;
cout << (x <= k) << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
25300 KB |
Output is correct |
2 |
Correct |
13 ms |
25340 KB |
Output is correct |
3 |
Incorrect |
16 ms |
25292 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
25300 KB |
Output is correct |
2 |
Correct |
13 ms |
25340 KB |
Output is correct |
3 |
Incorrect |
16 ms |
25292 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
128 ms |
54384 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
188 ms |
45716 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
25300 KB |
Output is correct |
2 |
Correct |
13 ms |
25340 KB |
Output is correct |
3 |
Incorrect |
16 ms |
25292 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
25300 KB |
Output is correct |
2 |
Correct |
13 ms |
25340 KB |
Output is correct |
3 |
Incorrect |
16 ms |
25292 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |