Codeforces Round #FF (Div. 2):C. DZY Loves Sequences[通俗易懂]

Codeforces Round #FF (Div. 2):C. DZY Loves Sequences

大家好,又见面了,我是全栈君。

C. DZY Loves Sequences
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

DZY has a sequence a, consisting of n integers.

We’ll call a sequence ai, ai + 1, …, aj (1 ≤ i ≤ j ≤ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment.

Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing.

You only need to output the length of the subsegment you find.

Input

The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers a1, a2, …, an (1 ≤ ai ≤ 109).

Output

In a single line print the answer to the problem — the maximum length of the required subsegment.

Sample test(s)
Input
6
7 2 3 1 5 6

Output
5

Note

You can choose subsegment a2, a3, a4, a5, a6 and change its 3rd element (that is a4) to 4.

题意就是, 你能够改变字符串中的一个字符。 就出其最长的连续字串

如案列, 7 2 3 1 5 6 —————7 2 3  4 5 6

输出即为5.


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<sstream>
#include<cmath>

using namespace std;

#define f1(i, n) for(int i=0; i<n; i++)
#define f2(i, m) for(int i=1; i<=m; i++)
#define f3(i, n) for(int i=n; i>=1; i--)
#define f4(i, n) for(int i=1; i<=n; i++)
#define f5(i, n) for(int i=2; i<=n; i++)
#define M 1005

const int INF = 0x3f3f3f3f;
int n, a[100005], b[100005];

int main()
{
    cin>>n;
    f4(i, n)
    cin>>a[i];
    b[1]=1;
    f5(i, n)
    {
        b[i]=1;
        if (a[i]>a[i-1])
            b[i]=b[i-1]+1;
    }
    int ans=-INF;
    f3(i, n)
    {
        if (b[i]==n)
            ans=max(b[i], ans);
        else
            ans=max(ans, b[i]+1);
        if (a[i-b[i]+1]-1>a[i-b[i]-1])
            ans=max(ans,b[i]+b[i-b[i]]);
        if (a[i-b[i]+2]-1>a[i-b[i]])
            ans=max(ans,b[i]+b[i-b[i]]);
    }
    cout<<ans<<endl;
    return 0;
}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/116123.html原文链接:https://javaforall.net

(0)
上一篇 2022年1月25日 下午8:00
下一篇 2022年1月25日 下午9:00


相关推荐

  • Nano-Banana实战教程:用SDXL Base 1.0生成带尺寸标注的工程级分解图

    Nano-Banana实战教程:用SDXL Base 1.0生成带尺寸标注的工程级分解图

    2026年3月13日
    2
  • jsp java 登陆界面代码_jsp登陆界面源代码

    jsp java 登陆界面代码_jsp登陆界面源代码展开全部 1 login jsp 文件 pageEncoding GB18030 gt 登录 afe59b9ee7ad 页面用户名 密码 type reset value 重置 style background color red gt 2 judge jsp 文件 pageEncoding GB18030 gt

    2026年3月26日
    2
  • fastRcNN算法路面病害检测_R语言经典算法

    fastRcNN算法路面病害检测_R语言经典算法  FastR-CNN算法是作者RossGirshick继R-CNN后的又一力作。R-CNN虽然取得了不错的成绩,但是其缺点也很明显。FastR-CNN同样使用VGG-16网络结构,与R-CNN相比训练时间快9倍,测试时间快213倍,准确率从62%提升至66%(再Pascalvoc数据集上)。FastR-CNN主要是解决R-CNN存在的问题:测试训练速度慢,主要是提取候选区域的特征慢:R-CNN首先从测试图中提取2000个候选区域,然后将这2000个候选区域分别输入到预训练好的CNN中提取特征

    2025年10月2日
    2
  • Python 函数解释:locals()

    Python 函数解释:locals()语法 locals 函数语法 locals 返回字典类型的局部变量 示例 In 3 deftest args a 1 b 1 print locals In 4 test test args test a 1 b 1

    2026年2月12日
    2
  • Prometheus时序数据库

    Prometheus时序数据库Prometheus时序数据库 一、Prometheus1、Prometheus安装1)源码安装prometheus安装包最新版本下载地址:https://prometheus.io/download/wgethttps://github.com/prometheus/prometheus/releases/download/v2.3.2/prometheus-2….

    2026年4月16日
    4
  • vps自建_七牛云搭建图床

    vps自建_七牛云搭建图床目的:将一些小服务应用部署到免费的serverless/VPS上去环境:0成本实现方式:github+vercel/freewha效果:项目一:个人导航项目二:个人博客项目三:个人音乐服务器:背景:上面的项目以前我都是部署在家里群晖上,或者VPS上,但是FRPC和VPS的流量,延时、运维更新等问题,实际用起来很繁琐,最近两年serverless发展很火,于是就萌生了把他们部署到免费的VPS或者serverless产品上网络上有很多hexo博客部署到vercel、github.

    2025年6月11日
    5

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号