제출 #333701

#제출 시각아이디문제언어결과실행 시간메모리
333701vipghn2003Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
0 / 100
1186 ms75128 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); } sort(vec.begin(),vec.end()); 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'; }

컴파일 시 표준 에러 (stderr) 메시지

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:56: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]
   56 |         while(j<vec.size()&&vec[j].fi<=i)
      |               ~^~~~~~~~~~~
sortbooks.cpp:64:17: warning: unused variable 'r' [-Wunused-variable]
   64 |             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...