bzoj3043IncDec Sequence

题意:

n个数,每次可以将区间l到r里的数+1或-1,问将它们变成同个数的最小操作次数和保证最小操作次数前提下有多少中可能。n≤100000。

题解:

先对原数组差分(得到的数组第一个为原数组第一个元素,之后的元素为原数组相邻元素之差),则原操作变为左右端点对应元素加1减1或减1加1,求最小操作次数使得除第一个元素之外剩下元素均为0。则先将正负数对消,剩下的数可以自己消掉或与第一个数对消,故第一问答案为max(正数之和,负数绝对值之和) 第二问答案为abs(正数之和-负数绝对值之和)+1。

代码:

 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define inc(i,j,k) for(int i=j;i<=k;i++)
#define maxn 100010
#define ll long long
using namespace std; inline ll read(){
char ch=getchar(); ll f=,x=;
while(ch<''||ch>''){if(ch=='-')f=-; ch=getchar();}
while(ch>=''&&ch<='')x=x*+ch-'',ch=getchar();
return f*x;
}
int n; ll day,xiy,a,b;
int main(){
n=read(); a=read(); inc(i,,n){b=read(); if(b-a>)day+=(b-a);else xiy+=(a-b); a=b;}
printf("%lld\n%lld",max(day,xiy),abs(day-xiy)+); return ;
}

20160929

bzoj3043IncDec Sequence*的更多相关文章

  1. oracle SEQUENCE 创建, 修改,删除

    oracle创建序列化: CREATE SEQUENCE seq_itv_collection            INCREMENT BY 1  -- 每次加几个              STA ...

  2. Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等

    功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...

  3. DG gap sequence修复一例

    环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...

  4. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  5. [LeetCode] Sequence Reconstruction 序列重建

    Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...

  6. [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列

    Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...

  7. [LeetCode] Verify Preorder Sequence in Binary Search Tree 验证二叉搜索树的先序序列

    Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary ...

  8. [LeetCode] Longest Consecutive Sequence 求最长连续序列

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

  9. [LeetCode] Permutation Sequence 序列排序

    The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

随机推荐

  1. webdriver中的等待

    强制等待:sleep() 设置固定休眠时间,单位为秒. 由python的time包提供, 导入 time 包后就可以使用. 缺点:不智能,使用太多的sleep会影响脚本运行速度. 隐式等待:impli ...

  2. 软件包,API,SDK的区别

    参考资料: https://www.jianshu.com/p/cac186cb168b https://blog.csdn.net/snowin1994/article/details/806080 ...

  3. 通过char与varchar的区别,学习可变长的字符类型

    转自http://www.uphtm.com/database/232.html 在mysql教程中char与varchar的区别呢,都是用来存储字符串的,只是他们的保存方式不一样罢了,char有固定 ...

  4. excel筛选重复项代码

    Sub test()'updateby Extendoffice 20151030    Dim xRng As Range    Dim xTxt As String    On Error Res ...

  5. MySQL语句的使用

    进入数据库  mysql -u root -pmysql    (u用户名,p密码)#如果不想让其他人看到就直接一个p然后回车再打密码 select version();   查看数据库版本 sele ...

  6. 多语言工作者の十日冲刺<1/10>

    这个作业属于哪个课程 软件工程 (福州大学至诚学院 - 计算机工程系) 这个作业要求在哪里 团队作业第五次--Alpha冲刺 这个作业的目标 团队进行Alpha冲刺--第一天(04.30) 作业正文 ...

  7. opencv C++矩阵操作

    int main(){ cv::Mat src1=(cv::Mat_<float>(2,3)<<1,2,3,4,5,6); cv::Mat src2=(cv::Mat_< ...

  8. vue 组件传参及跨域传参

    可以完成跨组件传参的四种方式 // 1) localStorage:永久存储数据 // 2) sessionStorage:临时存储数据(刷新页面数据不重置,关闭再重新开启标签页数据重置) // 3) ...

  9. ceph luminous版本的安装部署

    1. 前期准备   本次安装环境为:   ceph1(集群命令分发管控,提供磁盘服务集群) CentOs7.5 10.160.20.28   ceph2(提供磁盘服务集群) CentOs7.5 10. ...

  10. 关于阿里云服务器Linux安装Tomcat后,外网不能访问解决方案

    这里需要提及三个方面的问题   第一个方面:Linux上启动防火墙的问题 当下比较流行的Linux镜像是CentOS,所以防火墙也随之变成了firewall,那么怎么操作这个防火墙呢?   #停止fi ...