Submission #1096624

#TimeUsernameProblemLanguageResultExecution timeMemory
1096624rayan_bdHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
17 / 100
3043 ms262144 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; #define getar(ar,n) for(ll i=0;i<n;++i) cin>>ar[i] #define show(n) cout<<n<<'\n' #define all(v) v.begin(), v.end() #define br cout<<"\n" #define pb push_back #define nl '\n' #define yes cout<<"YES\n" #define no cout<<"NO\n" #define ret return #define ll long long #define ld long double #define sza(x) ((int)x.size()) const int mxN = 1e6 + 5; const ll MOD = 1e9 + 7; const ll INF = 1e18; const ld EPS = 1e-9; struct Node{ vector<ll> vec; ll mx=0,bad_mx=0; }; Node seg[mxN*4]; ll ar[mxN]; Node dummy_node; ll calc1(ll node){ ll lft_max=seg[node*2+1].mx; ll ans=-lft_max,st=0,en=seg[node*2+2].vec.size()-1; while(st<=en){ ll mid=st+(en-st)/2; if(seg[node*2+2].vec[mid]<lft_max){ st=mid+1; ans=seg[node*2+2].vec[mid]; }else{ en=mid-1; } } return ans+lft_max; } Node left_right_mrg(Node lft,Node rgt){ ll lft_max=lft.mx; ll ans=-lft_max,st=0,en=rgt.vec.size()-1; while(st<=en){ ll mid=st+(en-st)/2; if(rgt.vec[mid]<lft_max){ st=mid+1; ans=rgt.vec[mid]; }else{ en=mid-1; } } ans+=lft_max; Node curr; curr.bad_mx=max({lft.bad_mx,ans,rgt.bad_mx}); merge(all(lft.vec),all(rgt.vec),back_inserter(curr.vec)); curr.mx=max(lft.mx,rgt.mx); return curr; } void build(ll node,ll start,ll end){ if(start==end){ seg[node].vec.pb(ar[start]); seg[node].mx=ar[start]; seg[node].bad_mx=0; return; } ll mid=start+(end-start)/2; build(node*2+1,start,mid); build(node*2+2,mid+1,end); merge(all(seg[node*2+1].vec),all(seg[node*2+2].vec),back_inserter(seg[node].vec)); seg[node].bad_mx=max({seg[node*2+1].bad_mx,seg[node*2+2].bad_mx,calc1(node)}); seg[node].mx=max(seg[node*2+1].mx,seg[node*2+2].mx); } Node qry(ll nd,ll start,ll end,ll l,ll r){ if(start>r||end<l) return dummy_node; if(start>=l&&end<=r) return seg[nd]; ll mid=start+(end-start)/2; Node lft=qry(nd*2+1,start,mid,l,r); Node rgt=qry(nd*2+2,mid+1,end,l,r); if(lft.mx==-1) return rgt; else if(rgt.mx==-1) return lft; return left_right_mrg(lft,rgt); } void solve(){ ll n,l,r,w,q;cin>>n>>q; for(ll i=0;i<n;++i){ cin>>ar[i]; } dummy_node.mx=-1; build(0,0,n-1); while(q--){ cin>>l>>r>>w; cout<<(qry(0,0,n-1,l-1,r-1).bad_mx<=w)<<nl; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 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...