#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 arr[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] = {arr[l], arr[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;
auto x = Get(2 * node, l, mid, ql, qr);
auto y = Get(2 * node + 1, mid + 1, r, ql, qr);
return Merge(x, y);
}
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 >> arr[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 |
0 ms |
212 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 |
0 ms |
212 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 |
1326 ms |
31148 KB |
Output is correct |
2 |
Correct |
1324 ms |
30920 KB |
Output is correct |
3 |
Correct |
1308 ms |
30780 KB |
Output is correct |
4 |
Correct |
1335 ms |
30976 KB |
Output is correct |
5 |
Correct |
1305 ms |
30984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
97 ms |
3904 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 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 |
0 ms |
212 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 |
- |