AcWing
  • 首页
  • 课程
  • 题库
  • 更多
    • 竞赛
    • 题解
    • 分享
    • 问答
    • 应用
    • 校园
  • 关闭
    历史记录
    清除记录
    猜你想搜
    AcWing热点
  • App
  • 登录/注册

AcWing 4007. 非零段划分csp23(2)    原题链接    中等

作者: 作者的头像   YAX_AC ,  2024-11-29 22:19:29 ,  所有人可见 ,  阅读 17


2


#include<iostream>
#include<vector>

//观察题目 n≤5×10的5次方,且数组 A 中的每一个数均不超过 10的4次方。
//所以对于n去写O(n^2)一定会爆掉
//可以从数组A的值去考虑,从值域入手,不会爆掉
using namespace std;

const int N = 5*100010,M = 10010;

int n;
int a[N];
int st[N];
vector<int> p[N];

int main()
{
    cin>>n;
    for(int i = 1; i<=n; i++)
    {
        cin>>a[i];
        if(a[i]>0)
        {
            p[a[i]+1].push_back(i);
            st[i] = true;
        }
    }
    int now = 0;
    for(int i = 0; i<=n; i++)
        if(a[i]!=0 && a[i+1] == 0)
            now++;
    int max_now = 0;
    for(int i = 1; i<=M; i++)
    {
        for(auto j:p[i])
        {
            st[j] = false;//fase代表淹没
            //根据j点淹没时,j+1和j-1点的状态,判断now的变化
            if(st[j+1] && st[j-1]) now++;
            if(!st[j+1] && !st[j-1]) now--;
        }
        max_now = max(max_now,now);
    }
    cout<<max_now;
    return 0;
}

0 评论

App 内打开
你确定删除吗?
1024
x

© 2018-2025 AcWing 版权所有  |  京ICP备2021015969号-2
用户协议  |  隐私政策  |  常见问题  |  联系我们
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标 qq图标
请输入绑定的邮箱地址
请输入注册信息