A - DZY Loves Sequences
Posted thusloop
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了A - DZY Loves Sequences相关的知识,希望对你有一定的参考价值。
DZY Loves Sequences
b[i] 为 i 开始上升序列的右边界。
//#pragma GCC optimize(2)
//#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int inf=2e18+100;
const int maxn=2e5+100;
int a[maxn],b[maxn];
signed main()
{
IOS
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
if(n==1)
{
cout<<"1\\n";
return 0;
}
if(n==2)
{
cout<<"2\\n";
return 0;
}
int l=1,r=1;
while(r<=n)
{
if(l>=r)r=l+1;
while(r<=n&&a[r]>a[r-1])
{
r++;
}
b[l]=r-1;
l++;
//if(l>r)r=l+1;
}
for(int i=l;i<r;i++)b[i]=n;
int ans=1;
for(int i=1;i<=n;i++)
{
int l1=i,r1=b[i];
int l2=b[i]+1,r2=b[b[i]+1];
ans=max(ans,r1-l1+1);
if(l2>n)continue;
ans=max(ans,r2-l2+1);
if(r1-l1+1>1)
{
if(a[l2]-1>a[r1-1])ans=max(ans,r2-l1+1);
if(r2-l2+1>=1)ans=max(ans,r1-l1+2);
}
else if(r2-l2+1>=1)
{
ans=max(ans,r2-l2+2);
}
if(r2-l2+1>1)
{
if(a[l2+1]-1>a[r1])ans=max(ans,r2-l1+1);
if(r1-l1+1>=1)ans=max(ans,r2-l2+2);
}
else if(r1-l1+1>=1)
{
ans=max(ans,r1-l1+2);
}
}
cout<<ans<<"\\n";
}
以上是关于A - DZY Loves Sequences的主要内容,如果未能解决你的问题,请参考以下文章
[CodeForces - 447C] C - DZY Loves Sequences
Codeforces 447C - DZY Loves Sequences
CodeForces 446A. DZY Loves Sequences(最长上升子序列)
CodeForces 446A DZY Loves Sequences (DP+暴力)