#include <bits/stdc++.h>
using namespace std;
int n;
long long a[200005];
long long tree[200005];
long long row;
set<int>s[200005];
set<int>::iterator c;
void build(int id, int l, int r){
if(l == r){
tree[id] = a[l];
s[id].insert(a[l]);
return ;
}
int m = (l + r) / 2;
build(id * 2, l, m);
build(id * 2 + 1, m + 1, r);
std::merge(s[id*2].begin(), s[id*2].end(),
s[id*2+1].begin(), s[id*2+1].end(),
std::inserter(s[id], s[id].begin()));
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 up(int id, int L, int R, int l, int r, int itr){
if(R < l || r < L) return 0;
if(l <= L && R <= r) {
if(*s[id].begin() > itr) return 0;
c = s[id].lower_bound(itr);
c--;
return *c;
}
return max(up(id * 2, L, (L + R) / 2, l, r, itr) ,up(id * 2 + 1, (L + R) / 2 + 1, R, l, r, itr));
}
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);
long long k = up(1,1,n,m+1,r,x);
if(k == 0) return max(sit(l, m) , sit(m+1, r));
return max(sit(l, m) , max(sit(m+1, r) , k + x));
}
int main(){
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:56:12: warning: unused variable 'type' [-Wunused-variable]
56 | int type, l, r, x;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9676 KB |
Output is correct |
2 |
Correct |
6 ms |
9692 KB |
Output is correct |
3 |
Correct |
12 ms |
9800 KB |
Output is correct |
4 |
Correct |
6 ms |
9676 KB |
Output is correct |
5 |
Correct |
7 ms |
9696 KB |
Output is correct |
6 |
Correct |
25 ms |
9932 KB |
Output is correct |
7 |
Correct |
25 ms |
9964 KB |
Output is correct |
8 |
Correct |
35 ms |
9932 KB |
Output is correct |
9 |
Correct |
14 ms |
9804 KB |
Output is correct |
10 |
Incorrect |
29 ms |
9676 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9676 KB |
Output is correct |
2 |
Correct |
6 ms |
9692 KB |
Output is correct |
3 |
Correct |
12 ms |
9800 KB |
Output is correct |
4 |
Correct |
6 ms |
9676 KB |
Output is correct |
5 |
Correct |
7 ms |
9696 KB |
Output is correct |
6 |
Correct |
25 ms |
9932 KB |
Output is correct |
7 |
Correct |
25 ms |
9964 KB |
Output is correct |
8 |
Correct |
35 ms |
9932 KB |
Output is correct |
9 |
Correct |
14 ms |
9804 KB |
Output is correct |
10 |
Incorrect |
29 ms |
9676 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
89 ms |
23188 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
110 ms |
79360 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9676 KB |
Output is correct |
2 |
Correct |
6 ms |
9692 KB |
Output is correct |
3 |
Correct |
12 ms |
9800 KB |
Output is correct |
4 |
Correct |
6 ms |
9676 KB |
Output is correct |
5 |
Correct |
7 ms |
9696 KB |
Output is correct |
6 |
Correct |
25 ms |
9932 KB |
Output is correct |
7 |
Correct |
25 ms |
9964 KB |
Output is correct |
8 |
Correct |
35 ms |
9932 KB |
Output is correct |
9 |
Correct |
14 ms |
9804 KB |
Output is correct |
10 |
Incorrect |
29 ms |
9676 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9676 KB |
Output is correct |
2 |
Correct |
6 ms |
9692 KB |
Output is correct |
3 |
Correct |
12 ms |
9800 KB |
Output is correct |
4 |
Correct |
6 ms |
9676 KB |
Output is correct |
5 |
Correct |
7 ms |
9696 KB |
Output is correct |
6 |
Correct |
25 ms |
9932 KB |
Output is correct |
7 |
Correct |
25 ms |
9964 KB |
Output is correct |
8 |
Correct |
35 ms |
9932 KB |
Output is correct |
9 |
Correct |
14 ms |
9804 KB |
Output is correct |
10 |
Incorrect |
29 ms |
9676 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |