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. Android学习笔记上下文菜单

    布局文件main_activity.xml <?xml version="1.0" encoding="utf-8"?> <RelativeL ...

  2. 【JMeter_11】JMeter逻辑控制器__Switch控制器<Switch Controller>

    Switch控制器<Switch Controller> 业务逻辑: 取得switch value的值,通过对节点下所有取样器.逻辑控制器的下标.名称匹配去执行,switch value的 ...

  3. Windows安装C的编译环境

    对于java开发者来说安装C的编译环境不是非常熟悉,因此本文对C的安装环境进行介绍以及windows编译Redis和Zookeeper的过程.MinGW主要用于按照gcc.make等环境,cywin用 ...

  4. 黎活明8天快速掌握android视频教程--18_在SQLite中使用事务

    1 所谓的事业就是一系列的操作 比如:执行转账操作:将personid=1的账户转账10元到personid=2的账号中 所以的一系列操作就是:personid=1的账户钱要减少10元 personi ...

  5. python的一些基础知识

    一.函数介绍 二.模块与包 三.面向对象介绍 四.网络编程基础应用了解 五.基于MySQL对数据库的理解及基础操作 六.粗浅学习的前端知识整理

  6. 微信小程序预览Word文档

    <view data-url="https://xxxcom/attachment/word.docx" data-type="docx" catchta ...

  7. 入门大数据---Flume的搭建

    一.下载并解压到指定目录 崇尚授人以渔的思想,我说给大家怎么下载就行了,就不直接放连接了,大家可以直接输入官网地址 http://flume.apache.org ,一般在官网的上方或者左边都会有Do ...

  8. Python实用笔记 (12)函数式编程——高阶函数

    函数式编程的一个特点就是,允许把函数本身作为参数传入另一个函数,还允许返回一个函数! Python对函数式编程提供部分支持.由于Python允许使用变量,因此,Python不是纯函数式编程语言. 变量 ...

  9. Java使用IO流读取TXT文件

    通过BufferedReader读取TXT文件window系统默认的编码是GBK,而IDE的编码多数为UTF-8,如果没有规定new InputStreamReader(new FileInputSt ...

  10. Android详细介绍MPAndroidChart-LineChart

    在开发当中曲线图用的时候太多了,之前都是自己手写,之后发现太累还丑不符合需求 MPAndroidChart 先介绍LineChart 0.效果图 首先依赖  1. implementation 'co ...