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;
int n,d;
int a[300005];
int pozs[300005];
int dp[300005];
void calc_pozs()
{
for(int i=1;i<=n;i++)
{
int ult=i;
pozs[i]=i;
for(int j=i-1;j>0;j--)
{
if(ult-j>d)
break;
if(a[j]<a[i])
{
ult=j;
pozs[i]=j;
}
}
}
}
pair<int,int> ord2[300005];
int aint[1210000];
void upd(int nod, int st, int dr, int poz, int newv)
{
if(st==dr)
{
aint[nod]=newv;
return;
}
int mij=(st+dr)/2;
if(poz<=mij) upd(nod*2,st,mij,poz,newv);
else upd(nod*2+1,mij+1,dr,poz,newv);
aint[nod]=max(aint[nod*2],aint[nod*2+1]);
}
int qry(int nod, int st, int dr, int le, int ri)
{
if(le>ri)
return 0;
if(le==st && dr==ri)
return aint[nod];
int mij=(st+dr)/2;
return max(qry(nod*2,st,mij,le,min(mij,ri)),
qry(nod*2+1,mij+1,dr,max(mij+1,le),ri));
}
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>d;
for(int i=1;i<=n;i++)
cin>>a[i];
calc_pozs();
for(int i=1;i<=n;i++)
{
ord2[i]={a[i],-i};
}
sort(ord2+1,ord2+1+n);
int cur;
for(int i=1;i<=n;i++)
{
cur = -ord2[i].second;
dp[cur] = qry(1,1,n,pozs[cur],cur-1) + 1;
upd(1,1,n,cur,dp[cur]);
}
int rez=1;
for(int i=1;i<=n;i++)
rez=max(rez,dp[i]);
cout<<rez;
return 0;
}
# | 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... |