CodeForces722C Destroying Array【瞎搞】
题意:
先给你一个序列,然后给你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【瞎搞】的更多相关文章
- [codeforces722C]Destroying Array
[codeforces722C]Destroying Array 试题描述 You are given an array consisting of n non-negative integers a ...
- CodeForces-722C Destroying Array 并查集 离线操作
题目链接:https://cn.vjudge.net/problem/CodeForces-722C 题意 给个数组,每次删除一个元素,删除的元素作为一个隔断,问每次删除后该元素左右两边最大连续和 思 ...
- HDU5532 Almost Sorted Array(最长上升子序列 or 瞎搞个做差的数组)
题目链接:点我 题意:给定一个序列,询问是否能删除一个数让它成为非递减或者非递增的序列. 比如说 删除后的序列是1 3 3 5 或者5 3 3 1 或者1 3 5 或者5 3 1 都可以.只要满足删掉 ...
- Codeforces 722C. Destroying Array
C. Destroying Array time limit per test 1 second memory limit per test 256 megabytes input standard ...
- CF722C. Destroying Array[并查集 离线]
链接:Destroying Array C. Destroying Array time limit per test 1 second memory limit per test 256 megab ...
- URAL 1203. Scientific Conference(瞎搞)
题目链接 本来觉得这不是经典的贪心吗..果断水一次,wa了,看了看discuss,发现貌似不好水,土土的DP了一下,复杂度很高了,又T了...然后想想单调队列,二分什么的...不好往上加,直接搞了标记 ...
- Codeforces Gym 100610 Problem H. Horrible Truth 瞎搞
Problem H. Horrible Truth Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1006 ...
- B. Salty Fish Go! -期望题(瞎搞题)
链接:https://www.nowcoder.com/acm/contest/104/B来源:牛客网 题意:A few days ago, WRD was playing a small game ...
- TOJ3097: 单词后缀 (字典树 or map瞎搞)
传送门 (<---可以点击的~) 时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte 描述 有些英语单词后缀都是一样的,现在我们需要从给定的一堆单词里 ...
随机推荐
- PythonCookBook笔记——文件与IO
文件与IO 所有的程序都要处理输入与输出,涉及到文本.二进制文件.文件编码和对文件名.目录的操作. 读写文本数据 需要读写各种不同编码的文本数据,使用rt模式的open()函数. 该读写操作使用系统默 ...
- Arrays.sort(a) 自定义排序
Arrays.sort(a) 自定义排序,(需实现接口:Comparable) package com.hd; import java.util.Arrays; class Person imple ...
- HDU5363:Key Set
Problem Description soda has a set S with n integers {1,2,-,n}. A set is called key set if the sum o ...
- jvm -Xms -Xmx
1 -Xms -X表示这是一个“-X”参数,m即memory,s即start,这个是jvm初始可以使用的整个堆的大小. 2 -Xmx x表示max,jvm最大可以使用的整个堆的大小. 3 oracle ...
- Asynchronous programming with async and await (C#)
Asynchronous Programming with async and await (C#) | Microsoft Docs https://docs.microsoft.com/en-us ...
- Spark SQL includes a cost-based optimizer, columnar storage and code generation to make queries fast.
https://spark.apache.org/sql/ Performance & Scalability Spark SQL includes a cost-based optimize ...
- JVM无法启动,jps无法运行,提示内存不足
原因:系统设置中有设置了不允许over commit so,无法分配足够内存 /etc/sysctl.conf vm.overcommit_memory=1 或者sysctl vm.overco ...
- linux 启动引导器 grub,单用户模式:
Linux启动引导器 安装linux操作系统的时候就已经将启动引导器安装到硬盘上去了,才能通过硬盘的读取方式启动操作系统. 引导器分为2种: Lilo:功能比较简单,使用比较麻烦,后续发行版中使用gr ...
- 微信 jssdk 逻辑在 vue 中的运用
微信 jssdk 在 vue 中的简单使用 import wx from 'weixin-js-sdk'; wx.config({ debug: true, appId: '', timestamp: ...
- (转)定制findbugs规则
转载自http://www.51testing.com/html/97/13997-211893.html 这类文章极少,字节码操作需要对becl库及jvm字节码操作有一定常识.参考: http:// ...