题目描述 Description

  给定一个长度为n的数列{a1,a2...an},每次可以选择一个区间[l,r],使这个区间内的数都加一或者都减一。
  问至少需要多少次操作才能使数列中的所有数都一样,并求出在保证最少次数的前提下,最终得到的数列有多少种。

输入描述 Input Description

  第一行一个正整数n 
  接下来n行,每行一个整数,第i+1行的整数表示ai。

输出描述 Output Description

  第一行输出最少操作次数
  第二行输出最终能得到多少种结果

样例输入 Sample Input

4
1
1
2
2

样例输出 Sample Output

1
2

数据范围及提示 Data Size & Hint

  对于100%的数据,n=100000,0<=ai<2147483648。

/*
典型的差分题目
先做一个差分序列b,接下来就是怎么把除了b1之外的所有数都变成0,因为可以进行区间修改,那么对于序列b来说就是一个数加1的同时一个数减1,或一个数加1,或一个数减1。因为要求步数最少,所以要尽可能把加1用在负数上,把减1用在正数上,剩下的只有正数或负数时再单独加1或减1。至于方案数,取决于b1,那么我们要在不影响步数的情况下修改b1,那么只能把单独加1或减1换成修改b1和原来那个数。
*/
#include<cstdio>
#include<iostream>
#define M 100010
#define ll long long
using namespace std;
ll a[M],b[M];int n;
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
cin>>a[i];
b[i]=a[i]-a[i-];
}
ll tot1=,tot2=;
for(int i=;i<=n;i++)
if(b[i]>)tot1+=b[i];
else tot2-=b[i];
cout<<max(tot1,tot2)<<endl<<max(tot1-tot2,tot2-tot1)+;
return ;
}

IncDec Sequence(codevs 2098)的更多相关文章

  1. HDU 5860 Death Sequence(死亡序列)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  2. HDU 5783 Divide the Sequence(数列划分)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  3. HDU 1560 DNA sequence(DNA序列)

    HDU 1560 DNA sequence(DNA序列) Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K  ...

  4. 1085 Perfect Sequence (25 分)

    1085 Perfect Sequence (25 分) Given a sequence of positive integers and another positive integer p. T ...

  5. [PAT] 1140 Look-and-say Sequence(20 分)

    1140 Look-and-say Sequence(20 分)Look-and-say sequence is a sequence of integers as the following: D, ...

  6. 【BZOJ 3043】 3043: IncDec Sequence (差分)

    3043: IncDec Sequence Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 589  Solved: 332 Description 给 ...

  7. easyfinding(codevs 3280)

    3280 easyfinding  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description 给一个M 行N  列 ...

  8. (CodeForces - 5C)Longest Regular Bracket Sequence(dp+栈)(最长连续括号模板)

    (CodeForces - 5C)Longest Regular Bracket Sequence time limit per test:2 seconds memory limit per tes ...

  9. Bestcoder13 1003.Find Sequence(hdu 5064) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5064 题目意思:给出n个数:a1, a2, ..., an,然后需要从中找出一个最长的序列 b1, b ...

随机推荐

  1. Rootkit Hunter Sourcecode Learning

    目录 . Rootkit Hunter Introduce() . Source Code Frame() . do_system_check_initialisation() . do_system ...

  2. Rebar:Erlang构建工具

    Rebar是一款Erlang的构建工具,使用它可以方便的编译.测试erlang程序.内联驱动和打包Erlang发行版本. Rebar是一个独立的erlang脚本,所以使用Rebar发布程序非常简单,甚 ...

  3. Ubuntu学习总结-03 安装软件 & 技巧

    1 UBuntu 安装 Googole Chrome 首先下载软件 wget https://dl.google.com/linux/direct/google-chrome-stable_curre ...

  4. MyBatis查询传一个参数时报错:There is no getter for property named 'sleevetype' in 'class java.lang.Integer

    用MyBatis进行查询,传入参数只有一个时(非Map)如int,报错 There is no getter for property named 'sleevetype' in 'class jav ...

  5. 数数字 (Digit Counting,ACM/ICPC Danang 2007,UVa 1225)

    思路: 利用java 特性,将数字从1 一直加到n,全部放到String中,然后依次对strring扫描每一位,使其carr[str.charAt(i)-'0']++; 最后输出carr[i],即可. ...

  6. jQuery中prop()函数控制多选框(全选,反选)

    今天看了jQuery手册,对prop()函数又多了一点认识,记忆力不好,记录下来. prop() : 获取匹配元素集中第一个元素的值 判断checkbox中的第一个是否被选中: $(":ch ...

  7. mysql 出现错误Incorrect file format

    REPAIR TABLE xx_messages USE_FRM;

  8. java本地方法如何调用其他程序函数,方法详解2

    Java调用本地方法(JNI浅谈) (2006-11-27 14:55:36) 转载▼   分类: Java类文章                本人在项目开发实践中的总结和体会     前段时间公司 ...

  9. MongoDB的快速手动安装

    上一篇文章<MongoDB.WebIDE:升级版的Mongodb管理工具>漏了点东西:就是关于MongoDB主从库的安装配置和启动.网上关于MongoDB的安装有大量的文章供大家学习.我这 ...

  10. ubuntu显示桌面的快捷键,以及修改方法

    在ubuntu下面,快速显示桌面,你可以这样做. 1,ctrl+alt+d (默认的) 2,alt+tab 可以切换到桌面 但是我想把它修改成和windows一样的,我该怎么做呢? 其实很简单. 系统 ...