Submission #333699

#TimeUsernameProblemLanguageResultExecution timeMemory
333699vipghn2003Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
0 / 100
1182 ms75132 KiB
#include<bits/stdc++.h> #define pii pair<int,int> #define fi first #define se second #define mp make_pair using namespace std; const int N=1e6+5; int n,m,a[N]; struct Query { int l,r,k; }q[N]; vector<int>event[N]; vector<int>val; int BIT[N]; void update(int x,int val) { for(;x<=n;x+=x&-x) BIT[x]=max(BIT[x],val); } int get(int x) { int res=0; for(;x>=1;x-=x&-x) res=max(res,BIT[x]); return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin>>n>>m; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=m;i++) { cin>>q[i].l>>q[i].r>>q[i].k; event[q[i].r].push_back(i); } vector<pii>vec; stack<int>st; for(int i=1;i<=n;i++) { while(!st.empty()&&a[st.top()]<=a[i]) st.pop(); if(!st.empty()) vec.push_back(mp(i,st.top())); st.push(i); } int j=0; vector<int>res(m+1); for(int i=1;i<=n;i++) { while(j<vec.size()&&vec[j].fi<=i) { update(vec[j].se,a[vec[j].fi]+a[vec[j].se]); j++; } for(auto&id:event[i]) { int l=q[id].l; int r=q[id].r; int k=q[id].k; if(get(l)<=k) res[id]=1; else res[id]=0; } } for(int i=1;i<=m;i++) cout<<res[i]<<'\n'; }

Compilation message (stderr)

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:55:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         while(j<vec.size()&&vec[j].fi<=i)
      |               ~^~~~~~~~~~~
sortbooks.cpp:63:17: warning: unused variable 'r' [-Wunused-variable]
   63 |             int r=q[id].r;
      |                 ^
#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...