이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
vector<int>st,v,res;
void update(int i,int l,int r,int x,int k)
{
if(l==r)
{
st[i]=k;
return;
}
int m=(l+r)/2;
if(x<=m)update(i*2,l,m,x,k);
else update(i*2+1,m+1,r,x,k);
st[i]=max(st[2*i],st[2*i+1]);
}
int gsum(int i,int l,int r,int tl,int tr)
{
if(l>tr||tl>r||l>r)return 0;
if(tl<=l&&r<=tr)return st[i];
int m=(l+r)/2;
return max(gsum(2*i,l,m,tl,tr),gsum(i*2+1,m+1,r,tl,tr));
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,m,a,b,c;
cin>>n>>m;
vector<pair<int,pair<int,int>>>q[n];
res.resize(m);
st.resize(4*n+1);
for(int i=0;i<n;i++)
{
cin>>a;
v.push_back(a);
}
for(int i=0;i<m;i++)
{
cin>>a>>b>>c;
q[b-1].push_back({i,{a-1,c}});
}
stack<int>s;
for(int i=0;i<n;i++)
{
while(!s.empty())
{
if(v[s.top()]<=v[i])s.pop();
else break;
}
if(!s.empty())update(1,0,n-1,s.top(),v[s.top()]+v[i]);
s.push(i);
for(int j=0;j<q[i].size();j++)
{
if(gsum(1,0,n-1,q[i][j].second.first,i)<=q[i][j].second.second)res[q[i][j].first]=1;
else res[q[i][j].first]=0;
}
}
for(int i=0;i<m;i++)
{
cout<<res[i]<<"\n";
}
}
컴파일 시 표준 에러 (stderr) 메시지
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:52:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for(int j=0;j<q[i].size();j++)
| ~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |