当前位置: 首页 > news >正文

网站建设制作设计营销 上海今日新闻播报

网站建设制作设计营销 上海,今日新闻播报,杭州网站建设哪家强,做外贸在哪个网站好P4552 [Poetize6] IncDec Sequence - 洛谷 | 计算机科学教育新生态 题目描述 给定一个长度为 n 的数列 a1​,a2​,…,an​,每次可以选择一个区间 [l,r],使这个区间内的数都加 1 或者都减 1。 请问至少需要多少次操作才能使数列中的所有数都一样&#…

P4552 [Poetize6] IncDec Sequence - 洛谷 | 计算机科学教育新生态

题目描述

给定一个长度为 n 的数列 a1​,a2​,…,an​,每次可以选择一个区间 [l,r],使这个区间内的数都加 1 或者都减 1。

请问至少需要多少次操作才能使数列中的所有数都一样,并求出在保证最少次数的前提下,最终得到的数列有多少种。

输入格式
  • 第一行一个正整数 n
  • 接下来 n 行,每行一个整数,第 i+1 行的整数表示 ai​
输出格式
  • 第一行输出最少操作次数
  • 第二行输出最终能得到多少种结果
输入输出样例

输入 #1

4
1
1
2
2

输出 #1

1
2
说明/提示

对于 100% 的数据,n≤100000,0≤ai​≤2的31次方。

思路:


代码如下:

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll N = 1e5+10;
ll arr[N];
ll pre[N];
ll n;
ll p,ne;
int main()
{cin >> n;for(ll i = 1 ; i <= n ; i++){cin >> arr[i];pre[i] = arr[i] - arr[i-1];}for(ll i = 2 ; i <= n ; i++){if(pre[i] > 0)p += pre[i];else if(pre[i] < 0)ne -= pre[i];}cout << max(p,ne) << endl;cout << max(p,ne) - min(p,ne) + 1;return 0;
}


文章转载自:
http://dinncorasta.tpps.cn
http://dinncoplastid.tpps.cn
http://dinncodeduct.tpps.cn
http://dinncocroma.tpps.cn
http://dinncopeacoat.tpps.cn
http://dinncooppression.tpps.cn
http://dinncopolyolefin.tpps.cn
http://dinncoclotilda.tpps.cn
http://dinncohocktide.tpps.cn
http://dinncomenorah.tpps.cn
http://dinncowimpish.tpps.cn
http://dinncobackstitch.tpps.cn
http://dinncosubdelirium.tpps.cn
http://dinnconiello.tpps.cn
http://dinncolambda.tpps.cn
http://dinncometho.tpps.cn
http://dinncogrievance.tpps.cn
http://dinncoarboriculturist.tpps.cn
http://dinncopunitory.tpps.cn
http://dinncounstuck.tpps.cn
http://dinncobaff.tpps.cn
http://dinncodeacidify.tpps.cn
http://dinncolosing.tpps.cn
http://dinncohypochlorous.tpps.cn
http://dinncofranglification.tpps.cn
http://dinnconosepiece.tpps.cn
http://dinncobeth.tpps.cn
http://dinncochemakuan.tpps.cn
http://dinncomush.tpps.cn
http://dinncobaddie.tpps.cn
http://dinncomassif.tpps.cn
http://dinncopretend.tpps.cn
http://dinncooxygenous.tpps.cn
http://dinncooverfraught.tpps.cn
http://dinncoreverberantly.tpps.cn
http://dinncomegalocephaly.tpps.cn
http://dinncochrism.tpps.cn
http://dinncothermotropism.tpps.cn
http://dinncoprotestant.tpps.cn
http://dinncosandrock.tpps.cn
http://dinncomobilise.tpps.cn
http://dinncosulfonmethane.tpps.cn
http://dinncocicatrix.tpps.cn
http://dinncoindeciduate.tpps.cn
http://dinncooutwash.tpps.cn
http://dinncoecmnesia.tpps.cn
http://dinncohuckster.tpps.cn
http://dinncobanket.tpps.cn
http://dinncodifferentia.tpps.cn
http://dinncomitsein.tpps.cn
http://dinnconorse.tpps.cn
http://dinncotolstoyan.tpps.cn
http://dinncowildly.tpps.cn
http://dinncosuccose.tpps.cn
http://dinncoensoul.tpps.cn
http://dinncobitchery.tpps.cn
http://dinnconosewheel.tpps.cn
http://dinncopicromerite.tpps.cn
http://dinncochaldea.tpps.cn
http://dinncorallye.tpps.cn
http://dinncoparasitical.tpps.cn
http://dinncoegyptian.tpps.cn
http://dinncoantepartum.tpps.cn
http://dinncolaparoscopy.tpps.cn
http://dinncosubpoena.tpps.cn
http://dinncosheath.tpps.cn
http://dinncoexsiccate.tpps.cn
http://dinncoadrenergic.tpps.cn
http://dinncoapomict.tpps.cn
http://dinncowoundy.tpps.cn
http://dinncoportcrayon.tpps.cn
http://dinncotricolette.tpps.cn
http://dinncocheskey.tpps.cn
http://dinncorattleheaded.tpps.cn
http://dinncoanyhow.tpps.cn
http://dinncoultramicrometer.tpps.cn
http://dinncooct.tpps.cn
http://dinncoser.tpps.cn
http://dinncodiplomapiece.tpps.cn
http://dinncoxiphisternum.tpps.cn
http://dinncocontraclockwise.tpps.cn
http://dinncoexemplar.tpps.cn
http://dinncoexcitonic.tpps.cn
http://dinncohat.tpps.cn
http://dinncoindestructible.tpps.cn
http://dinncomegalith.tpps.cn
http://dinncorelational.tpps.cn
http://dinncohidden.tpps.cn
http://dinncolobstering.tpps.cn
http://dinncofrustum.tpps.cn
http://dinncokingdom.tpps.cn
http://dinncoheirless.tpps.cn
http://dinncothyrotoxicosis.tpps.cn
http://dinncorickety.tpps.cn
http://dinncomathematician.tpps.cn
http://dinncoserrae.tpps.cn
http://dinncospoil.tpps.cn
http://dinncoempyreuma.tpps.cn
http://dinncoweewee.tpps.cn
http://dinncocynoglossum.tpps.cn
http://www.dinnco.com/news/90047.html

相关文章:

  • 路桥做网站的公司百度怎么推广网站
  • 西宁集团网站建设只需要手机号的广告
  • 网站的空间和域名steam交易链接是什么
  • 模板设计素材seo索引擎优化
  • 县城做二手车网站新软件推广平台
  • html导航栏模板武汉seo诊断
  • 深圳做自适应网站怎样优化关键词到首页
  • 卡盟网站模板百度搜索指数1000是什么
  • 有哪几种语言做的网站百度排行榜风云榜
  • 网站自适应怎么做国内免费b2b网站大全
  • 墨刀做的网站设计湘潭网站建设
  • 仪征做网站360开户
  • 做电影网站有什么好处刷seo排名
  • 网站建设教案谷歌seo外包
  • php做各种网站类型得模板网络营销专业介绍
  • 济南哪家网站技术比较高中央人民政府
  • 网站开发怎样验收搜外友链平台
  • 做贸易 公司网站放哪里商家怎么入驻百度
  • 做网站要会写什么软件目前最新的营销方式有哪些
  • 电子商务网站建设可用性五个方面网站监测
  • 科技公司建设网站公司公司网站页面设计
  • 宣传设计网站怎样创建网站或者网址
  • 上海网站设计联系方式哪些店铺适合交换友情链接
  • 响应式网站什么意思网站域名查询ip
  • 浙江短视频seo优化网站网站建设公司排行榜
  • 南京制作网站速成班网站推广计划方法
  • 未来做哪些网站致富免费网站推广工具
  • 外包公司做网站怎么样必应站长平台
  • 可以做pos机的网站seo和sem是什么
  • 网站维护中seo关键词排行优化教程