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;
const int nx=2e5+5;
int n, l, r, dp[nx], ans;
vector<int> upd[nx];
struct fenwick
{
int d[nx];
void update(int i, int vl) {while (i<nx) d[i]=max(d[i], vl), i+=(i&-i);}
int query(int i)
{
int res=0;
while (i>0) res=max(res, d[i]), i-=(i&-i);
return res;
}
} f;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n;
for (int i=1; i<=n; i++)
{
cin>>l>>r;
for (auto x:upd[i]) f.update(x, dp[x]);
dp[i]=f.query(max(0, i-l-1))+1;
upd[min(n+1, i+r+1)].push_back(i);
ans=max(ans, dp[i]);
}
cout<<ans;
}
# | 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... |