Submission #564577

#TimeUsernameProblemLanguageResultExecution timeMemory
564577uroskHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
0 / 100
1278 ms106552 KiB
#include <bits/stdc++.h> #define here cerr<<"------------------------------------\n" #define ll long long #define pll pair<ll,ll> #define all(a) a.begin(),a.end() #define fi first #define sc second #define pb push_back #define popb pop_back #define sz(x) (ll)(x.size()) #define llinf 100000000000000LL #define endl '\n' #define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;} using namespace std; #define maxn 1000005 ll n,q; ll a[maxn]; ll b[maxn]; ll t[4*maxn]; ll ans[maxn]; struct upit{ ll l,r,x,id; }; bool cmp(upit a,upit b){return a.r<b.r;} void upd(ll v,ll tl,ll tr,ll i,ll x){ if(tl==tr){ t[v] = max(t[v],x); return; } ll mid = (tl+tr)/2; if(i<=mid) upd(2*v,tl,mid,i,x); else upd(2*v+1,mid+1,tr,i,x); t[v] = max(t[2*v],t[2*v+1]); } ll get(ll v,ll tl,ll tr,ll l,ll r){ if(l>r) return 0; if(tl==l&&tr==r) return t[v]; ll mid = (tl+tr)/2; return max(get(2*v,tl,mid,l,min(mid,r)),get(2*v+1,mid+1,tr,max(mid+1,l),r)); } vector<upit> v; int main(){ ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0); cin >> n >> q; for(ll i = 1;i<=n;i++) cin >> a[i]; stack<ll> st; for(ll i = 1;i<=n;i++){ while(sz(st)&&a[i]>a[st.top()]) st.pop(); if(sz(st)) b[i] = st.top(); st.push(i); } for(ll i = 1;i<=q;i++){ ll l,r,x; cin >> l >> r >> x; v.pb({l,r,x,i}); } sort(all(v),cmp); ll j = 1; for(upit p : v){ ll l = p.l; ll r = p.r; ll x = p.x; ll id = p.id; while(j<=r){ if(b[j]!=0) upd(1,1,n,b[j],a[j] + a[b[j]]); j++; } ans[id] = get(1,1,n,l,r)<=x; } for(ll i = 1;i<=q;i++) cout<<ans[i]<<endl; }
#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...