Submission #321540

#TimeUsernameProblemLanguageResultExecution timeMemory
321540ryanseeHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
0 / 100
2604 ms145388 KiB
#include "bits/stdc++.h" using namespace std; #define FAST ios_base::sync_with_stdio(false); cin.tie(0); #define pb push_back #define eb emplace_back #define ins insert #define f first #define s second #define cbr cerr<<"hi\n" #define mmst(x, v) memset((x), v, sizeof ((x))) #define siz(x) ll(x.size()) #define all(x) (x).begin(), (x).end() #define lbd(x,y) (lower_bound(all(x),y)-x.begin()) #define ubd(x,y) (upper_bound(all(x),y)-x.begin()) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng) inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); } using ll=int; using ld=long double; #define FOR(i,s,e) for(ll i=s;i<=ll(e);++i) #define DEC(i,s,e) for(ll i=s;i>=ll(e);--i) using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; #define LLINF INF //((long long)1e18) #define INF int(1e9+1e6) #define MAXN (1000006) struct node { int v,add,base; node*l,*r; node(int S,int E){ int s=S,e=E,m=(s+e)>>1; v=-LLINF, add=-LLINF, base=0; if(s^e)l=new node(s,m),r=new node(m+1,e); } void update(int s,int e,int x,int y,int nval) { value(s,e); int m=(s+e)>>1; if(s==x&&e==y) { add = max(add, nval); return; } if(x>m) r->update(m+1,e,x,y,nval); else if(y<=m) l->update(s,m,x,y,nval); else l->update(s,m,x,m,nval),r->update(m+1,e,m+1,y,nval); v = max(l->value(s,m), r->value(m+1,e)); base = max(l->base, r->base); } ll rmq(int s,int e,int x,int y) { if(x>y) return -LLINF; value(s,e); int m=(s+e)>>1; if(s==x&&e==y) return v; if(x>m) return r->rmq(m+1,e,x,y); else if(y<=m) return l->rmq(s,m,x,y); else return max(l->rmq(s,m,x,m), r->rmq(m+1,e,m+1,y)); } void set(int s,int e,int x,int nval) { value(s,e); if(s==e) { v = nval + base; return; } int m=(s+e)>>1; if(x>m) r->set(m+1,e,x,nval); else l->set(s,m,x,nval); v = max(l->value(s,m), r->value(m+1,e)); base = max(l->base, r->base); } ll value(int s,int e) { v = max(v, add + base); if(s^e) { l->add=max(l->add, add); r->add=max(r->add, add); } add=-LLINF; return v; } void set_base(int s,int e,int x,int nval) { value(s,e); if(s==e) { v-= base, base = nval, v+=base; return; } int m=(s+e)>>1; if(x>m) r->set_base(m+1, e, x, nval); else l->set_base(s, m, x, nval); v = max(l->value(s,m), r->value(m+1,e)); base = max(l->base, r->base); } } *seg; int n,m,A[MAXN]; bool can[MAXN]; vector<int> v; vector<pi> ans; vector<tuple<int,int,int>> Q[MAXN]; #define gc getchar_unlocked ll in(){ ll x=0; char ch=gc(); while(ch<'0'||ch>'9') ch=gc(); while(ch>='0'&&ch<='9') { x=(x<<3)+(x<<1)+(ch&15); ch=gc(); } return x; } int main() { n=in(),m=in(); FOR(i,1,n)A[i]=in(); seg=new node(1, n); FOR(i,1,m) { ll l,r,k; l=in(), r=in(), k=in(); Q[r].pb({l, k, i}); } auto add_ans=[&](ll ind,ll val) { while(ans.size()&&ans.back().s<=val)ans.pop_back(); ans.eb(ind,val); }; auto add=[&](ll x){ while(v.size() && A[v.back()] <= A[x]) { add_ans(v.back(), seg->rmq(1, n, siz(v),siz(v))); seg->set(1, n, siz(v), -LLINF); v.pop_back(); } v.eb(x); seg->set_base(1, n, siz(v), A[x]); }; auto upd=[&](ll x){ ll st=-1, en=siz(v); while(en-st>1){// highest ind that is still > x ll mid=(st+en)>>1; if(A[v[mid]] > x) st=mid; else en=mid; } if(st<0) return; seg->update(1, n, 1, st+1, x); }; FOR(r,1,n) { upd(A[r]); add(r); for(auto q:Q[r]) { ll l=get<0>(q); ll ind = lbd(v, l) + 1; ll mx = max(ans[lbd(ans, pi(l,-LLINF))].s, seg->rmq(1, n, ind, siz(v))); if(mx <= get<1>(q)) can[get<2>(q)]=1; } } FOR(i,1,m) cout<<can[i]<<'\n'; }
#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...