Submission #992772

#TimeUsernameProblemLanguageResultExecution timeMemory
992772simona1230Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
0 / 100
3066 ms262144 KiB
#include <bits/stdc++.h> using namespace std; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } long long n,m,a[1000001]; void read() { cin>>n>>m; for(long long i=1;i<=n;i++) cin>>a[i]; } long long maxx[1000001][32]; long long minn[1000001][32]; long long pw[1000001]; void prec() { long long x=1,y=0; while(x<=n) { pw[x]=y; if(x+1==(1<<(y+1))) y++; x++; } for(long long i=1;i<=n;i++) maxx[i][0]=minn[i][0]=a[i]; for(long long j=1;j<20;j++) { for(long long i=1;i<=n;i++) { minn[i][j]=min(minn[i][j-1],minn[i+(1<<(j-1))][j-1]); maxx[i][j]=max(maxx[i][j-1],maxx[i+(1<<(j-1))][j-1]); } } } long long max_(long long l,long long r) { long long len=r-l+1; return max(maxx[l][pw[len]],maxx[r-(1<<(pw[len]))+1][pw[len]]); } long long min_(long long l,long long r) { long long len=r-l+1; return min(minn[l][pw[len]],minn[r-(1<<(pw[len]))+1][pw[len]]); } void solve() { for(long long i=1;i<=m;i++) { long long l,r,k; cin>>l>>r>>k; long long ans=0; for(long long j=l;j<r;j++) { ans=max(ans,max_(l,j)-min_(j+1,r)); } if(ans<=k)cout<<1<<endl; else cout<<0<<endl; } } int main() { speed(); read(); prec(); solve(); 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...