设 为以 结尾的最长严格递增子段长度, 为以 开头的最长严格递增子段长度。
对于元素 ,有以下三种操作: 1.修改 ,使前后两个连续上升序列拼接; 2.修改 ,加到前面的上升序列的尾部; 3.修改 ,加到前面的上升序列的头部。
综上所述,设修改的数为 ,其严格递增子段长度为:
code
#include<bits/stdc++.h>
#define ll long long
#define rll register ll
#define F(i,a,b) for(rll i=a;i<=b;i++)
#define Fdn(i,a,b) for(rll i=a;i>=b;i--)
//#define int ll
#define itn int
using namespace std;
const int inf = 0x3f3f3f3f,mod = 1e9 + 7;
const int maxn = 1e5 + 7;
int a[maxn];
int l[maxn];
int r[maxn];
int n , ans;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
n = read();
F(i,1,n)
a[i] = read();
F(i,1,n)
l[i] = (a[i] > a[i - 1]) ? l[i - 1] + 1 : 1;
Fdn(i,n,1)
r[i] = (a[i] < a[i + 1]) ? r[i + 1] + 1 : 1;
F(i,1,n)
ans = ((a[i + 1] - a[i - 1] >= 2) ? max(ans , l[i - 1] + r[i + 1] + 1) : max(ans , max(l[i - 1],r[i + 1]) + 1));
write(ans);
return 0;
}少了读写函数,读者自行添加。