#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 1e6 + 2;
const int inf = 2e9;
struct node {
int mx, mn, ans;
}st[4 * N];
int a[N];
node Merge(node a, node b) {
node c;
c.ans = max(a.ans, b.ans);
if (a.mx > b.mn) smax(c.ans, a.mx + b.mn);
c.mx = max(a.mx, b.mx);
c.mn = min(a.mn, b.mn);
return c;
}
void Init(int node, int l, int r) {
if (l == r) {
st[node] = {a[l], a[l], 0};
return;
}
int mid = l + r >> 1;
Init(2 * node, l, mid);
Init(2 * node + 1, mid + 1, r);
st[node] = Merge(st[2 * node], st[2 * node + 1]);
}
node Get(int node, int l, int r, int ql, int qr) {
if (r < ql || qr < l) return {-inf, inf, 0};
if (ql <= l && r <= qr) return st[node];
int mid = l + r >> 1;
return Merge(Get(2 * node, l, mid, ql, qr), Get(2 * node + 1, mid + 1, r, ql, qr));
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> a[i];
Init(1, 0, n - 1);
while (m--) {
int l, r, x;
cin >> l >> r >> x;
l -= 1; r -= 1;
node ans = Get(1, 0, n - 1, l, r);
if (ans.ans <= x) cout << 1 << en;
else cout << 0 << en;
}
return 0;
}
Compilation message
sortbooks.cpp: In function 'void Init(int, int, int)':
sortbooks.cpp:28:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
28 | int mid = l + r >> 1;
| ~~^~~
sortbooks.cpp: In function 'node Get(int, int, int, int, int)':
sortbooks.cpp:36:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
36 | int mid = l + r >> 1;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1332 ms |
62780 KB |
Output is correct |
2 |
Correct |
1330 ms |
63768 KB |
Output is correct |
3 |
Correct |
1319 ms |
63620 KB |
Output is correct |
4 |
Correct |
1317 ms |
63704 KB |
Output is correct |
5 |
Correct |
1329 ms |
63716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
100 ms |
5912 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |