Submission #172639

#TimeUsernameProblemLanguageResultExecution timeMemory
172639LinusTorvaldsFanHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
0 / 100
3019 ms5224 KiB
#include <bits/stdc++.h> using namespace std; const int maxn=1000000+7; int w[maxn]; const int K=1000; int block_answer[maxn/K+1]; int block_max[maxn/K+1]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); // freopen("input.txt","r",stdin); int n,m; cin>>n>>m; for(int i=0;i<n;i++)cin>>w[i]; for(int i=0;i+K-1<n;i+=K){ int block=i/K; block_answer[block]=-1; for(int l=i;l<i+K;l++){ for(int r=l+1;r<i+K;r++){ if(w[l]>w[r]){ block_answer[block]=max(block_answer[block],w[l]+w[r]); } } } for(int l=i;l<i+K;l++){ block_max[block]=max(block_max[block],w[l]); } //cout<<block_answer[block]<<" "; //cout<<block_max[block]<<endl; } // build(n); for(;m;m--){ int l,r,k; cin>>l>>r>>k; l--; r--; int ans=-1; int max_left=-1; for(;l%K!=0 && l <= r;l++){ //int q=get(l+1,r+1,w[l]); //cout<<q<<endl; //if(q!=-1) ans=max(ans,w[l]+q); if(w[l]<max_left){ ans=2e9+7; } max_left=max(w[l],max_left); } for(;l+K-1<=r;l+=K){ int block=l/K; ans=max(ans,block_answer[block]); // int q=get(l+K,r+1,block_max[block]); // cout<<":"<<q<<"\n"; // if(q!=-1) ans=max(ans,block_max[block]+q); if(block_max[block]<max_left){ ans=2e9+7; } max_left=max(max_left,block_max[block]); } for(;l<=r;l++){ // int q=get(l+1,r+1,w[l]); // cout<<q<<endl; // if(q!=-1) ans=max(ans,w[l]+q); if(w[l]<max_left){ ans=2e9+7; } max_left=max(w[l],max_left); } // cout<<ans<<endl; if(ans<=k){ cout<<1<<'\n'; } else { cout<<0<<'\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...