题意:

先给你一个序列,然后给你n个1-n的一个数,让你求前i个元素销毁的时候,区间字段和区间最大;

思路:

离线处理,维护新区间首尾位置的起点和终点,倒着处理;

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int>PII;
const double eps=1e-5;
const double pi=acos(-1.0);
//const int mod=1e9+7;
const int INF=0x3f3f3f3f; const int N=1e5+10;
struct asd{
int s,t;
};
asd q[N]; LL a[N];
LL ans[N],sum[N];
int sp[N],temp[N]; int main()
{
int n;
scanf("%d",&n);
sum[0]=0;
for(int i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
sum[i]=sum[i-1]+a[i];
}
for(int i=1;i<=n;i++)
scanf("%d",&sp[i]); memset(temp,0,sizeof(temp));
for(int i=1;i<=n;i++)
q[i].s=q[i].t=i; ans[n]=0;
LL TMAX=0;
for(int i=n;i>=2;i--)
{
temp[sp[i]]=1;
if(temp[sp[i]-1])
q[sp[i]].s=q[sp[i]-1].s;
if(temp[sp[i]+1])
q[sp[i]].t=q[sp[i]+1].t;
q[q[sp[i]].t].s=q[sp[i]].s;
q[q[sp[i]].s].t=q[sp[i]].t;
TMAX=max(TMAX,sum[q[sp[i]].t] - sum[q[sp[i]].s-1]);
ans[i-1]=TMAX;
// printf("%d %d\n",q[sp[i]].s,q[sp[i]].t);
}
for(int i=1;i<=n;i++)
printf("%lld\n",ans[i]);
return 0;
}

CodeForces722C Destroying Array【瞎搞】的更多相关文章

  1. [codeforces722C]Destroying Array

    [codeforces722C]Destroying Array 试题描述 You are given an array consisting of n non-negative integers a ...

  2. CodeForces-722C Destroying Array 并查集 离线操作

    题目链接:https://cn.vjudge.net/problem/CodeForces-722C 题意 给个数组,每次删除一个元素,删除的元素作为一个隔断,问每次删除后该元素左右两边最大连续和 思 ...

  3. HDU5532 Almost Sorted Array(最长上升子序列 or 瞎搞个做差的数组)

    题目链接:点我 题意:给定一个序列,询问是否能删除一个数让它成为非递减或者非递增的序列. 比如说 删除后的序列是1 3 3 5 或者5 3 3 1 或者1 3 5 或者5 3 1 都可以.只要满足删掉 ...

  4. Codeforces 722C. Destroying Array

    C. Destroying Array time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. CF722C. Destroying Array[并查集 离线]

    链接:Destroying Array C. Destroying Array time limit per test 1 second memory limit per test 256 megab ...

  6. URAL 1203. Scientific Conference(瞎搞)

    题目链接 本来觉得这不是经典的贪心吗..果断水一次,wa了,看了看discuss,发现貌似不好水,土土的DP了一下,复杂度很高了,又T了...然后想想单调队列,二分什么的...不好往上加,直接搞了标记 ...

  7. Codeforces Gym 100610 Problem H. Horrible Truth 瞎搞

    Problem H. Horrible Truth Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1006 ...

  8. B. Salty Fish Go! -期望题(瞎搞题)

    链接:https://www.nowcoder.com/acm/contest/104/B来源:牛客网 题意:A few days ago, WRD was playing a small game ...

  9. TOJ3097: 单词后缀 (字典树 or map瞎搞)

    传送门 (<---可以点击的~) 时间限制(普通/Java):1000MS/3000MS     内存限制:65536KByte 描述 有些英语单词后缀都是一样的,现在我们需要从给定的一堆单词里 ...

随机推荐

  1. MapReduce 1工作原理图文详解

    MapReduce工作原理图文详解 一 MapReduce程序执行流程 程序执行流程图如下: 流程分析:1.在客户端启动一个作业.2.向JobTracker请求一个Job ID.3.将运行作业所需要的 ...

  2. Javascript学习之Date对象详解

    1.定义 创建 Date 实例用来处理日期和时间.Date 对象基于1970年1月1日世界协调时起的毫秒数 2.语法 构造函数 new Date() new Date(value) value代表自世 ...

  3. windows搭建FTP服务器实战

    第一步:创建用户名密码(ftp使用) 1.1.点击“开始”菜单,选择“控制面板”. 1.2.选择“管理工具”—>“计算机管理” 1.3. 选择“本地用户和组”下的用户,右键选择“新用户” 输入用 ...

  4. s:if

    <s:iterator value="value[3]" id="ques" status="s"> <s:if test ...

  5. js实现菜单二级联动

    代码如下,以便自己以后方便查阅: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> < ...

  6. git命令行删除远程分支

    先查看远程分支 git branch -r 使用下面两条命令来删除远程分支 git branch -r -d origin/branch-name git push origin :branch-na ...

  7. hadoop内存分配方案

    Configuration File   Configuration Setting Value Calculation        8G VM (4G For MR)    yarn-site.x ...

  8. codeforces 664A A. Complicated GCD(水题)

    题目链接: A. Complicated GCD time limit per test 1 second memory limit per test 256 megabytes input stan ...

  9. ubuntu 下编译安装ceph

    git clone --recursive https://github.com/ceph/ceph.git  cd ceph/  sudo apt-get install libtool   sud ...

  10. c/c++生成预编译文件

    Preprocesses C and C++ source files and writes the preprocessed output to a file.   /P Remarks The f ...