#include <bits/stdc++.h>
using namespace std;
int a[1000005];
const int inf = 1e9;
struct node {
int ans, mn, mx;
} seg[4000005];
void build (int l, int r, int id) {
if (l == r) {
seg[id].ans = 0;
seg[id].mn = seg[id].mx = a[l];
return;
}
build(l, (l+r)/2, id*2);
build((l+r)/2+1, r, id*2+1);
seg[id].ans = max({seg[id*2].ans, seg[id*2+1].ans, seg[id*2].mx - seg[id*2+1].mn});
seg[id].mn = min(seg[id*2].mn, seg[id*2+1].mn);
seg[id].mx = max(seg[id*2].mx, seg[id*2+1].mx);
}
node query (int l, int r, int id, int ql, int qr) {
if (qr < l || r < ql) return {0, inf, 0};
if (ql <= l && r <= qr) return seg[id];
node u = query(l, (l+r)/2, id*2, ql, qr), v = query((l+r)/2+1, r, id*2+1, ql, qr);
return {max({u.ans, v.ans, u.mx - v.mn}), min(u.mn, v.mn), max(u.mx, v.mx)};
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
build(1, n, 1);
while (m--) {
int l, r, k;
cin >> l >> r >> k;
cout << (query(1, n, 1, l, r).ans <= k) << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1096 ms |
64756 KB |
Output is correct |
2 |
Incorrect |
1064 ms |
65724 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
76 ms |
8784 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |