This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
vector<int>st;
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(2*i,l,m,x,k);
else update(2*i+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(2*i+1,m+1,r,tl,tr));
}
int main()
{
int n,sum=0,a,b;
cin>>n;
vector<pair<int,int>>v;
st.resize(4*n+1);
vector<int>dp(n),q[2*n+1];
for(int i=0;i<n;i++)
{
cin>>a>>b;
v.push_back({a,b});
}
for(int i=0;i<n;i++)
{
for(int j=0;j<q[i].size();j++)
{
update(1,0,n-1,q[i][j],dp[q[i][j]]);
}
dp[i]=1+gsum(1,0,n-1,0,i-v[i].first-1);
sum=max(sum,dp[i]);
q[i+v[i].second+1].push_back(i);
}
cout<<sum;
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:37:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | 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... |