이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define xx first
#define yy second
#define MAXN 200010
using namespace std;
int n, x, a[MAXN], b[MAXN], dp[MAXN], lvd[MAXN], ress=-1; ///lvd=lis veci desno
int binarna(int cnt, int k)
{
int l=0, r=cnt-1;
int ret=-1;
while (l<=r)
{
int mid=l+(r-l)/2;
if (dp[mid]<k)
{
ret=mid;
l=mid+1;
}
else
r=mid-1;
}
return ret;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n>>x;
int maxx=-1;
for (int i=0; i<n; i++) { cin>>a[i]; maxx=max(maxx, a[i]); }
for (int i=0; i<n; i++) b[i]=maxx-a[i];
dp[0]=b[n-1];
int cnt=1;
lvd[n-1]=0; lvd[n-2]=0;
if (a[n-1]>(a[n-2]-x)) lvd[n-2]=1;
for (int i=n-2; i>/*=*/0; i--)
{
if (b[i]<dp[0]) dp[0]=b[i];
else if (b[i]>dp[cnt-1]) dp[cnt++]=b[i];
else
{
if (find(dp, dp+cnt, b[i])==dp+cnt)
{
auto it=upper_bound(dp, dp+cnt, b[i]);
*it=b[i];
}
}
int kolko=a[i-1]-x;
//cout<<i-1<<" "<<maxx-kolko<<" "<<cnt<<endl;
lvd[i-1]=binarna(cnt, maxx-kolko)+1;
}
//for (int i=0; i<n; i++) cout<<lvd[i]<<" ";
//cout<<endl;
for (int i=0; i<=n; i++) dp[i]=0;
a[0]-=x;
dp[0]=a[0];
ress=max(ress, lvd[0]+1);
cnt=1;
for (int i=1; i<n; i++)
{
a[i]-=x;
if (a[i]<dp[0]) dp[0]=a[i];
else if (a[i]>dp[cnt-1]) dp[cnt++]=a[i];
else
{
if (find(dp, dp+cnt, a[i])==dp+cnt)
{
auto it=upper_bound(dp, dp+cnt, a[i]);
*it=a[i];
}
}
int kolko=binarna(cnt, a[i]);
kolko++;
ress=max(ress, (kolko+lvd[i]+1));
}
ress=max(ress, cnt);
cout<<ress;
}
/*
15
20
1 7 3 20 8 3 17 10 3 27 14 17 13 9 15
5
10
1 4 2 7 10
5
1
1 4 2 7 10
*/
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |