#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6;
int n, m, arr[N + 5];
struct info {
int res = 0, mx = 0, mn = 1e18;
info operator+(info x) {
info ans;
ans.res = mx > x.mn ? mx + x.mn : 0;
ans.mx = max(mx, x.mx);
ans.mn = min(mn, x.mn);
return ans;
}
};
info tree[4*N + 5];
void update(int v, int tl, int tr, int k, int x) {
if (tl == tr) tree[v].mx = tree[v].mn = x;
else {
int tm = (tl + tr)/2;
if (k <= tm) update(v*2, tl, tm, k, x);
else update(v*2 + 1, tm + 1, tr, k, x);
tree[v] = tree[v*2] + tree[v*2 + 1];
}
}
info query(int v, int tl, int tr, int l, int r) {
if (l > r) {
info ans;
return ans;
} else if (tl == l && tr == r) {
return tree[v];
} else {
int tm = (tl + tr)/2;
return query(v*2, tl, tm, l, min(tm, r)) + query(v*2 + 1, tm + 1, tr, max(l, tm + 1), r);
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
update(1, 1, n, i, arr[i]);
}
for (int i = 1; i <= m; i++) {
int l, r, k;
cin >> l >> r >> k;
info res = query(1, 1, n, l, r);
if (res.res <= k) cout << 1 << '\n';
else cout << 0 << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1210 ms |
91128 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
84 ms |
9432 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |