Submission #1184484

#TimeUsernameProblemLanguageResultExecution timeMemory
1184484zhamshidHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++20
0 / 100
10 ms9800 KiB
#include <bits/stdc++.h> #define noSuccess t-- #define int long long #define pb push_back #define F first #define S second #define Sattar_is_the_best ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define all(s) s.begin(),s.end() #define yes "YES\n" #define no "NO\n" #define sz size using namespace std; const int maxn = 1e5; const int mod = 1e9 + 7; int n,q,a[maxn],p[maxn],t[maxn]; int l[maxn],r[maxn],k[maxn]; vector<pair<int,int>>Q[maxn]; vector<int>add[maxn]; void upd(int v,int tl,int tr,int pos,int val){ if(tl==tr){ t[v]=val; return; } int mid = tl + tr >> 1; if(mid<=pos) upd(v+v,tl,mid,pos,val); else upd(v+v+1,mid+1,tr,pos,val); t[v]=max(t[v+v],t[v+v+1]); } int get(int v,int tl,int tr,int l,int r){ if(tl>r || tr<l) return 0; if(l<=tl && tr<=r) return t[v]; int mid = tl + tr >> 1; return max(get(v+v,tl,mid,l,r),get(v+v+1,mid+1,tr,l,r)); } int ans[maxn]; void tryAgain(){ cin>>n>>q; for(int i=1;i<=n;i++){ cin>>a[i]; } stack<int>st; for(int i=1;i<=n;i++){ while(!st.empty() && a[st.top()]<=a[i]){ st.pop(); } if(st.empty()) p[i]=0; else p[i]=st.top(); st.push(i); add[i].pb(p[i]); } for(int i=1;i<=q;i++){ cin>>l[i]>>r[i]>>k[i]; Q[l[i]].pb({r[i],i}); } for(int L=n;L>=1;L--){ for(auto to : add[L]){ upd(1,1,n,L,a[L]+a[to]); } for(auto to : Q[L]){ // cout<<get(1,1,n,L,to.F)<<' '<<k[to.S]<<'\n'; ans[to.S]=(get(1,1,n,L,to.F)<=k[to.S] ? 1 : 0); } } for(int i=1;i<=q;i++){ cout<<ans[i]<<'\n'; } } signed main(){ Sattar_is_the_best // freopen("length.in", "r", stdin); // freopen("length.out", "w", stdout); int t = 1; // cin >> t; while(noSuccess){ tryAgain(); } }
#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...