Submission #286903

#TimeUsernameProblemLanguageResultExecution timeMemory
286903dvdg6566Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
17 / 100
3084 ms20832 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=1001000; 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)); } }*maxes; int fs[MAXN]; vpi V; int main(){ ios_base::sync_with_stdio(0);cin.tie(0); cin>>N>>Q; for(int i=1;i<=N;++i){ cin>>A[i]; } stack<int> S; for(int i=1;i<=N;++i){ while(SZ(S) && A[S.top()] <= A[i]){ // cerr<<"Inversion "<<S.top()<<' '<<i<<'\n'; S.pop(); } if(SZ(S)){ V.pb(S.top(),i); // cerr<<"Inversion "<<S.top()<<' '<<i<<'\n'; } S.push(i); } while(Q--){ cin>>a>>b>>c; int fail=0; for(auto i:V){ if(i.f >= a && i.s <= b && A[i.f] + A[i.s] > c){ fail=1; } } if(fail)cout<<"0\n"; else cout<<"1\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...