#include <bits/stdc++.h>
#define int long long
using namespace std;
int n;
long long a[1000005],i;
long long tree[1000005];
long long row;
void build(int id, int l, int r){
if(l == r){
tree[id] = a[l];
return ;
}
int m = (l + r) / 2;
build(id * 2, l, m);
build(id * 2 + 1, m + 1, r);
tree[id] = max(tree[id * 2] ,tree[id * 2 + 1]);
}
long long query(int id, int L, int R, int l, int r){
if(R < l || r < L) return 0;
if(l <= L && R <= r) {
return tree[id];
}
return max(query(id * 2, L, (L + R) / 2, l, r) ,query(id * 2 + 1, (L + R) / 2 + 1, R, l, r));
}
long long sit(int l, int r){
int m = (l + r) / 2;
if(l == r) return 0;
int x = query(1,1,n,l,m);
int k = 0;
for(i = m+1;i <= l;i++){
if(a[i] < x) k = max(k,a[i]);
}
return max(sit(l, m) , max(sit(m+1, r) , k + x));
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int Q;
cin >> n;
cin >> Q;
for(int i = 1; i <= n; i++) cin >> a[i];
build(1, 1, n);
while(Q--){
int type, l, r, x;
cin >> l >> r >> x;
if(sit(l,r) > x) cout << '0' << endl;
else cout << '1' << endl;
}
return 0;
}
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:45:12: warning: unused variable 'type' [-Wunused-variable]
45 | int type, l, r, x;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
3 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
3 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
118 ms |
31780 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3088 ms |
3044 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
3 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
3 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |