#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 7;
int a[N], lg[N + 1], s[21][N + 1], st[21][N + 1], mx[N];
int get(int l, int r) {
if(l > r)return 0;
int le = lg[r - l + 1];
return max(s[l][le], s[r - (1 << le) + 1][le]);
}
int gett(int l, int r) {
if(l > r)return 0;
int le = lg[r - l + 1];
return max(st[l][le], st[r - (1 << le) + 1][le]);
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m;
cin>>n>>m;
for(int i = 1; i <= n; i++) {
cin>>a[i];
s[i][0] = a[i];
}
lg[1] = 0;
for (int i = 2; i <= N; i++)lg[i] = lg[i / 2] + 1;
for(int i = 1; i <= 20; i++){
for(int x = 1; x + (1 << i) - 1 <= n; x++){
s[x][i] = max(s[x][i - 1], s[x + (1 << (i - 1))][i - 1]);
}
}
set<int> ss;
for(int i = 1; i <= n; i++) {
if(get(i + 1, n) < a[i]) {
mx[i] = a[i] + get(i + 1, n);
ss.insert(-i);
st[i][0] = mx[i];
break;
}
int l = i + 1, r = n, res = i + 1;
while(l <= r) {
int m = (l + r) >> 1;
if(get(i + 1, m) >= a[i])r = m - 1, res = m;
else l = m + 1;
}
if((i + 1) == res)mx[i] = 0;
else {
mx[i] = a[i] + get(i + 1, res - 1);
ss.insert(-i);
}
st[i][0] = mx[i];
}
for(int i = 1; i <= 20; i++){
for(int x = 1; x + (1 << i) - 1 <= n; x++){
st[x][i] = max(st[x][i - 1], st[x + (1 << (i - 1))][i - 1]);
}
}
while(m --) {
int l, r, k;
cin>>l>>r>>k;
int pos = *ss.lower_bound(-r);
pos = -pos;
if(pos > r || pos < l) {
cout << "0\n";
continue;
}
int ans = gett(l, pos - 1);
ans = max(ans, a[pos] + get(pos + 1, r));
cout << ((ans > k) ? 0 : 1) << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
29020 KB |
Output is correct |
2 |
Incorrect |
2 ms |
14684 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
29020 KB |
Output is correct |
2 |
Incorrect |
2 ms |
14684 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
44 ms |
91948 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
44 ms |
91984 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
29020 KB |
Output is correct |
2 |
Incorrect |
2 ms |
14684 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
29020 KB |
Output is correct |
2 |
Incorrect |
2 ms |
14684 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |