제출 #286909

#제출 시각아이디문제언어결과실행 시간메모리
286909dvdg6566Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
17 / 100
6 ms1408 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pi; typedef vector<ll> vi; typedef vector<pi> vpi; #define pb emplace_back #define mp make_pair #define f first #define s second #define SZ(x) (int)x.size() #define ALL(x) x.begin(),x.end() #define lb lower_bound const int MAXN=10010; const ll MOD=998244353; int A[MAXN]; int N,Q,a,b,c; struct node{ int s,e,m,v; node *l,*r; node(int _s,int _e):s(_s),e(_e){ m=(s+e)/2;v=0; if(s!=e){ l=new node(s,m); r=new node(m+1,e); v=max(l->v,r->v); } } int ask(int a,int b){ if(a==s&&e==b)return v; if(b<=m)return l->ask(a,b); if(a>m)return r->ask(a,b); return max(l->ask(a,m),r->ask(m+1,b)); } void up(int x,int va){ if(s==e){ v=max(va,v); return; } if(x<=m)l->up(x,va); else r->up(x,va); v=max(l->v,r->v); } }*root; int fs[MAXN]; vpi V; int endpt[MAXN]; typedef pair<int,pi> pp; vector<pp> queries[MAXN]; int out[MAXN]; int main(){ ios_base::sync_with_stdio(0);cin.tie(0); cin>>N>>Q; for(int i=1;i<=N;++i){ cin>>A[i]; } root=new node(1,N); stack<int> S; for(int i=1;i<=N;++i){ while(SZ(S) && A[S.top()] <= A[i]){ S.pop(); } if(SZ(S)){ // V.pb(S.top(),i); endpt[i]=S.top(); } S.push(i); } for(int i=0;i<Q;++i){ cin>>a>>b>>c; queries[b].pb(i,mp(a,c)); } for(int e=1;e<=N;++e){ if(endpt[e]){ root->up(endpt[e], A[endpt[e]] + A[e]); // cerr<<"Up "<<endpt[e]<<' '<<A[endpt[e]]+A[e]<<'\n'; } for(auto i:queries[e]){ int t=root->ask(i.s.f, e); if(t<=i.s.s)out[i.f]=1; // cerr<<t<<' '<<i.s.s<<'\n'; } } for(int i=0;i<Q;++i){ cout<<out[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...