#include<bits/stdc++.h>
using namespace std;
vector<int64_t>extra;
vector<vector<int64_t>>tree;
void build(vector<int64_t>&arr,int64_t node,int64_t node_low,int64_t node_high){
if (node_low==node_high){
tree[node].push_back(arr[node_low]);
}
else {
int64_t mid =(node_low+node_high)>>1;
build(arr,node*2,node_low,mid);
build(arr,node*2 + 1,mid+1,node_high);
extra[node] = max(extra[node*2],extra[node*2 + 1]);
auto right = lower_bound(tree[node*2 + 1].begin(),tree[node*2 + 1].end(),tree[node*2].back()) - tree[node*2 + 1].begin();
while(right>=0){
if (tree[node*2 + 1][right]>=tree[node*2].back() || right>=(int)tree[node*2 + 1].size()){
--right;
}
else break;
}
if (right>=0){
extra[node] = max(extra[node],tree[node*2].back() + tree[node*2 + 1][right]);
}
merge(tree[2*node].begin(),tree[2*node].end(),tree[2*node + 1].begin(),tree[2*node + 1].end(),back_inserter(tree[node]));
}
}
int64_t curans = 0;
int64_t maxxy = 0;
void query(int64_t node,int64_t node_low,int64_t node_high,int64_t query_low,int64_t query_high){
if (node_low>node_high||query_high<node_low||query_low>node_high)return ;
if (query_low<=node_low&&query_high>=node_high){
curans = max(curans,extra[node]);
auto right = lower_bound(tree[node].begin(),tree[node].end(),maxxy) - tree[node].begin();
while(right>=0){
if (tree[node][right]>=maxxy || right>=(int)tree[node].size()){
--right;
}
else break;
}
if (right>=0){
curans = max(curans,maxxy + tree[node][right]);
}
maxxy = max(maxxy,tree[node].back());
return ;
}
int64_t mid = (node_low+node_high)>>1;
query(node*2,node_low,mid,query_low,query_high);
query(node*2 + 1,mid+1,node_high,query_low,query_high);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int64_t n,m;cin>>n>>m;
vector<int64_t>arr(n);
for (int64_t i = 0;i<n;++i){
cin>>arr[i];
}
extra.resize(4*n,0);
tree.resize(4*n);
build(arr,1,0,n-1);
for (int64_t i = 0;i<m;++i){
int64_t l,r,k;cin>>l>>r>>k;
--l,--r;
curans = 0;
maxxy = 0;
query(1,0,n-1,l,r);
//cout<<curans<<" "<<maxxy<<'\n';
if (curans>k){
cout<<0<<'\n';
}
else cout<<1<<'\n';
}
return 0;}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
724 KB |
Output is correct |
12 |
Correct |
4 ms |
1876 KB |
Output is correct |
13 |
Correct |
5 ms |
1876 KB |
Output is correct |
14 |
Correct |
7 ms |
2004 KB |
Output is correct |
15 |
Correct |
7 ms |
2004 KB |
Output is correct |
16 |
Correct |
8 ms |
2004 KB |
Output is correct |
17 |
Correct |
4 ms |
1492 KB |
Output is correct |
18 |
Correct |
5 ms |
2016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
380 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
226 ms |
34756 KB |
Output is correct |
2 |
Correct |
242 ms |
34800 KB |
Output is correct |
3 |
Correct |
250 ms |
34756 KB |
Output is correct |
4 |
Correct |
261 ms |
34744 KB |
Output is correct |
5 |
Correct |
265 ms |
34756 KB |
Output is correct |
6 |
Correct |
130 ms |
34784 KB |
Output is correct |
7 |
Correct |
158 ms |
34804 KB |
Output is correct |
8 |
Correct |
191 ms |
34732 KB |
Output is correct |
9 |
Correct |
48 ms |
524 KB |
Output is correct |
10 |
Correct |
201 ms |
34700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
724 KB |
Output is correct |
12 |
Correct |
4 ms |
1876 KB |
Output is correct |
13 |
Correct |
5 ms |
1876 KB |
Output is correct |
14 |
Correct |
7 ms |
2004 KB |
Output is correct |
15 |
Correct |
7 ms |
2004 KB |
Output is correct |
16 |
Correct |
8 ms |
2004 KB |
Output is correct |
17 |
Correct |
4 ms |
1492 KB |
Output is correct |
18 |
Correct |
5 ms |
2016 KB |
Output is correct |
19 |
Correct |
633 ms |
70840 KB |
Output is correct |
20 |
Correct |
632 ms |
70844 KB |
Output is correct |
21 |
Correct |
539 ms |
70840 KB |
Output is correct |
22 |
Correct |
546 ms |
70792 KB |
Output is correct |
23 |
Correct |
462 ms |
70860 KB |
Output is correct |
24 |
Correct |
501 ms |
70828 KB |
Output is correct |
25 |
Correct |
465 ms |
70900 KB |
Output is correct |
26 |
Correct |
442 ms |
70896 KB |
Output is correct |
27 |
Correct |
553 ms |
70804 KB |
Output is correct |
28 |
Correct |
662 ms |
70792 KB |
Output is correct |
29 |
Correct |
547 ms |
70832 KB |
Output is correct |
30 |
Correct |
667 ms |
70872 KB |
Output is correct |
31 |
Correct |
597 ms |
70780 KB |
Output is correct |
32 |
Correct |
664 ms |
70872 KB |
Output is correct |
33 |
Correct |
728 ms |
70936 KB |
Output is correct |
34 |
Correct |
364 ms |
70820 KB |
Output is correct |
35 |
Correct |
461 ms |
70868 KB |
Output is correct |
36 |
Correct |
440 ms |
70792 KB |
Output is correct |
37 |
Correct |
466 ms |
70852 KB |
Output is correct |
38 |
Correct |
370 ms |
70780 KB |
Output is correct |
39 |
Correct |
489 ms |
70872 KB |
Output is correct |
40 |
Correct |
334 ms |
42248 KB |
Output is correct |
41 |
Correct |
549 ms |
70820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
724 KB |
Output is correct |
12 |
Correct |
4 ms |
1876 KB |
Output is correct |
13 |
Correct |
5 ms |
1876 KB |
Output is correct |
14 |
Correct |
7 ms |
2004 KB |
Output is correct |
15 |
Correct |
7 ms |
2004 KB |
Output is correct |
16 |
Correct |
8 ms |
2004 KB |
Output is correct |
17 |
Correct |
4 ms |
1492 KB |
Output is correct |
18 |
Correct |
5 ms |
2016 KB |
Output is correct |
19 |
Runtime error |
380 ms |
262144 KB |
Execution killed with signal 9 |
20 |
Halted |
0 ms |
0 KB |
- |