제출 #539349

#제출 시각아이디문제언어결과실행 시간메모리
5393491neHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
64 / 100
728 ms262144 KiB
#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;}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...