#include<bits/stdc++.h>
using namespace std;
vector<int64_t>extra;
void combine(vector<int64_t>tree1,vector<int64_t>tree2,int64_t node){
/*for (auto x:tree1){
cout<<x<<" ";
}
cout<<" - > ";
for (auto x:tree2){
cout<<x<<" ";
}
cout<<'\n';
*/
extra[node] = max(extra[node*2],extra[node*2 + 1]);
auto right = upper_bound(tree2.begin(),tree2.end(),tree1.back()) - tree2.begin();
while(right>=0){
if (tree2[right]>=tree1.back() || right>=(int)tree2.size()){
--right;
}
else break;
}
if (right>=0){
extra[node] = max(extra[node],tree1.back() + tree2[right]);
}
// if there is a element in right segment which is less than left maximum
}
pair<vector<int64_t>,int64_t> combine2(pair<vector<int64_t>,int64_t>tree11,pair<vector<int64_t>,int64_t>tree22){
pair<vector<int64_t>,int64_t> ans;
ans.second = max(tree11.second,tree22.second);
vector<int64_t>tree1 = tree11.first;
vector<int64_t>tree2 = tree22.first;
auto right = upper_bound(tree2.begin(),tree2.end(),tree1.back()) - tree2.begin();
while(right>=0){
if (tree2[right]>=tree1.back()|| right>=(int)tree2.size()){
--right;
}
else break;
}
if (right>=0){
ans.second = max(ans.second,tree1.back() + tree2[right]);
}
merge(tree1.begin(),tree1.end(),tree2.begin(),tree2.end(),back_inserter(ans.first));
return ans;
}
void build(vector<vector<int64_t>>&tree,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(tree,arr,node*2,node_low,mid);
build(tree,arr,node*2 + 1,mid+1,node_high);
combine(tree[2*node],tree[node*2 + 1],node);
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(vector<vector<int64_t>>&tree,int64_t node,int64_t node_low,int64_t node_high,int64_t query_low,int64_t query_high){
if (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 = upper_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(tree,node*2,node_low,mid,query_low,query_high);
query(tree,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];
}
vector<vector<int64_t>>tree(4*n);
extra.resize(4*n,0);
build(tree,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(tree,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 |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
456 KB |
Output is correct |
7 |
Correct |
1 ms |
468 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 |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
456 KB |
Output is correct |
7 |
Correct |
1 ms |
468 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 |
4 ms |
724 KB |
Output is correct |
12 |
Correct |
6 ms |
2004 KB |
Output is correct |
13 |
Correct |
6 ms |
1996 KB |
Output is correct |
14 |
Correct |
7 ms |
2120 KB |
Output is correct |
15 |
Correct |
8 ms |
2140 KB |
Output is correct |
16 |
Correct |
6 ms |
2132 KB |
Output is correct |
17 |
Correct |
5 ms |
1492 KB |
Output is correct |
18 |
Correct |
9 ms |
2108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
439 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
253 ms |
35580 KB |
Output is correct |
2 |
Correct |
215 ms |
35224 KB |
Output is correct |
3 |
Correct |
404 ms |
35112 KB |
Output is correct |
4 |
Correct |
319 ms |
35184 KB |
Output is correct |
5 |
Correct |
349 ms |
35148 KB |
Output is correct |
6 |
Correct |
281 ms |
35180 KB |
Output is correct |
7 |
Correct |
329 ms |
35148 KB |
Output is correct |
8 |
Correct |
905 ms |
35140 KB |
Output is correct |
9 |
Correct |
38 ms |
912 KB |
Output is correct |
10 |
Correct |
1434 ms |
35104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
456 KB |
Output is correct |
7 |
Correct |
1 ms |
468 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 |
4 ms |
724 KB |
Output is correct |
12 |
Correct |
6 ms |
2004 KB |
Output is correct |
13 |
Correct |
6 ms |
1996 KB |
Output is correct |
14 |
Correct |
7 ms |
2120 KB |
Output is correct |
15 |
Correct |
8 ms |
2140 KB |
Output is correct |
16 |
Correct |
6 ms |
2132 KB |
Output is correct |
17 |
Correct |
5 ms |
1492 KB |
Output is correct |
18 |
Correct |
9 ms |
2108 KB |
Output is correct |
19 |
Correct |
538 ms |
72068 KB |
Output is correct |
20 |
Correct |
539 ms |
71888 KB |
Output is correct |
21 |
Correct |
428 ms |
71968 KB |
Output is correct |
22 |
Correct |
435 ms |
72120 KB |
Output is correct |
23 |
Correct |
475 ms |
72056 KB |
Output is correct |
24 |
Correct |
347 ms |
71936 KB |
Output is correct |
25 |
Correct |
369 ms |
72108 KB |
Output is correct |
26 |
Correct |
456 ms |
72056 KB |
Output is correct |
27 |
Correct |
450 ms |
71968 KB |
Output is correct |
28 |
Correct |
466 ms |
71972 KB |
Output is correct |
29 |
Correct |
526 ms |
71968 KB |
Output is correct |
30 |
Correct |
467 ms |
71944 KB |
Output is correct |
31 |
Correct |
469 ms |
72136 KB |
Output is correct |
32 |
Correct |
472 ms |
71948 KB |
Output is correct |
33 |
Correct |
480 ms |
71900 KB |
Output is correct |
34 |
Correct |
321 ms |
71864 KB |
Output is correct |
35 |
Correct |
421 ms |
71972 KB |
Output is correct |
36 |
Correct |
340 ms |
72008 KB |
Output is correct |
37 |
Correct |
302 ms |
71928 KB |
Output is correct |
38 |
Correct |
349 ms |
71968 KB |
Output is correct |
39 |
Correct |
374 ms |
71968 KB |
Output is correct |
40 |
Correct |
303 ms |
43624 KB |
Output is correct |
41 |
Execution timed out |
3055 ms |
71524 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
456 KB |
Output is correct |
7 |
Correct |
1 ms |
468 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 |
4 ms |
724 KB |
Output is correct |
12 |
Correct |
6 ms |
2004 KB |
Output is correct |
13 |
Correct |
6 ms |
1996 KB |
Output is correct |
14 |
Correct |
7 ms |
2120 KB |
Output is correct |
15 |
Correct |
8 ms |
2140 KB |
Output is correct |
16 |
Correct |
6 ms |
2132 KB |
Output is correct |
17 |
Correct |
5 ms |
1492 KB |
Output is correct |
18 |
Correct |
9 ms |
2108 KB |
Output is correct |
19 |
Runtime error |
439 ms |
262144 KB |
Execution killed with signal 9 |
20 |
Halted |
0 ms |
0 KB |
- |