当前位置:网站首页>1700C - Helping the Nature
1700C - Helping the Nature
2022-07-06 17:59:00 【Stellaris_ L】
subject
The question
Give an array , There are three operations ,
- (1) Will be in the array a 1 ∼ a i a_1\sim a_i a1∼ai Minus one .
- (2) Will be in the array a i ∼ a n a_i\sim a_n ai∼an Minus one .
- (3) Add one to all the numbers in the array .
Change all the numbers of the array into 0 Minimum operands of .
Using differential arrays , Convert the original array to all zeros into the difference group to all zeros . You can convert the original operation .
- (1) b 1 − 1 b_1-1 b1−1, b i + 1 b_i+1 bi+1.
- (2) b i − 1 b_i-1 bi−1.
- (3) b 1 + 1 b_1+1 b1+1.
therefore , Only operation is found (1) Can divide 1 Add one to other numbers , Only operation (2) Can divide 1 Subtract one from the outside , So you just need to divide the difference group 1 Deal with other places , Last use (2)(3) Operation judgment position 1 Can .
Pay attention to it long long.
#include <iostream>
using namespace std;
typedef long long ll;
const int N=2e5+10;
ll T,a[N],b[N];
void slove(){
int n;
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)b[i]=a[i]-a[i-1];
ll ans=0;
for(int i=2;i<=n;i++){
if(b[i]>0)ans+=b[i];
else if(b[i]<0){
ans-=b[i];
b[1]+=b[i];
}
}
cout<<ans+abs(b[1])<<endl;
}
int main(){
cin>>T;while(T--)
slove();
return 0;
}
边栏推荐
- Sqoop I have everything you want
- scratch疫情隔离和核酸检测模拟 电子学会图形化编程scratch等级考试三级真题和答案解析2022年6月
- HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅
- Distinguish between basic disk and dynamic disk RAID disk redundant array
- Four processes of program operation
- Solution qui ne peut pas être retournée après la mise à jour du navigateur Web flutter
- In terms of byte measurement with an annual salary of 30W, automated testing can be learned in this way
- Getting started with pytest ----- test case rules
- 2022年大厂Android面试题汇总(二)(含答案)
- There is a gap in traditional home decoration. VR panoramic home decoration allows you to experience the completion effect of your new house
猜你喜欢
Basic configuration and use of spark
在一台服务器上部署多个EasyCVR出现报错“Press any to exit”,如何解决?
The integrated real-time HTAP database stonedb, how to replace MySQL and achieve nearly a hundredfold performance improvement
Unity particle special effects series - treasure chest of shining stars
Zen integration nails, bugs, needs, etc. are reminded by nails
历史上的今天:Google 之母出生;同一天诞生的两位图灵奖先驱
Scratch epidemic isolation and nucleic acid detection Analog Electronics Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022
RB157-ASEMI整流桥RB157
[elastic] elastic lacks xpack and cannot create template unknown setting index lifecycle. name index. lifecycle. rollover_ alias
SAP UI5 框架的 manifest.json
随机推荐
一体化实时 HTAP 数据库 StoneDB,如何替换 MySQL 并实现近百倍性能提升
Grafana 9 is officially released, which is easier to use and more cool!
Debug and run the first xv6 program
The integrated real-time HTAP database stonedb, how to replace MySQL and achieve nearly a hundredfold performance improvement
[elastic] elastic lacks xpack and cannot create template unknown setting index lifecycle. name index. lifecycle. rollover_ alias
Jerry's updated equipment resource document [chapter]
Binary search strategy
Remote code execution penetration test - B module test
The difference between parallelism and concurrency
基于STM32+华为云IOT设计的智能路灯
Four processes of program operation
Jerry's watch deletes the existing dial file [chapter]
Pourquoi Li shufu a - t - il construit son téléphone portable?
Getting started with pytest ----- test case rules
Selected technical experts from China Mobile, ant, SF, and Xingsheng will show you the guarantee of architecture stability
STM32按键状态机2——状态简化与增加长按功能
偷窃他人漏洞报告变卖成副业,漏洞赏金平台出“内鬼”
78 岁华科教授逐梦 40 载,国产数据库达梦冲刺 IPO
Kernel link script parsing
Unity粒子特效系列-闪星星的宝箱