当前位置:网站首页>1700C - Helping the Nature
1700C - Helping the Nature
2022-07-06 17:59:00 【Stellaris_ L】
subject
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-LPovsZs2-1656470420013)(C:/Users/ Li Junlin /AppData/Roaming/Typora/typora-user-images/image-20220629102534925.png)]](/img/ce/49712244660d81007040c2ab42c5bf.png)
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;
}
边栏推荐
- Spark calculation operator and some small details in liunx
- SQL statement optimization, order by desc speed optimization
- Nodejs 开发者路线图 2022 零基础学习指南
- 容器里用systemctl运行服务报错:Failed to get D-Bus connection: Operation not permitted(解决方法)
- 偷窃他人漏洞报告变卖成副业,漏洞赏金平台出“内鬼”
- Mysqlimport imports data files into the database
- 重磅硬核 | 一文聊透对象在 JVM 中的内存布局,以及内存对齐和压缩指针的原理及应用
- QT中Model-View-Delegate委托代理机制用法介绍
- Video fusion cloud platform easycvr adds multi-level grouping, which can flexibly manage access devices
- VR panoramic wedding helps couples record romantic and beautiful scenes
猜你喜欢

2022年大厂Android面试题汇总(二)(含答案)

Solution qui ne peut pas être retournée après la mise à jour du navigateur Web flutter
![[getting started with MySQL] fourth, explore operators in MySQL with Kiko](/img/11/66b4908ed8f253d599942f35bde96a.png)
[getting started with MySQL] fourth, explore operators in MySQL with Kiko

STM32按键状态机2——状态简化与增加长按功能

2022年大厂Android面试题汇总(一)(含答案)

What is the reason why the video cannot be played normally after the easycvr access device turns on the audio?

scratch疫情隔离和核酸检测模拟 电子学会图形化编程scratch等级考试三级真题和答案解析2022年6月

分布式不来点网关都说不过去

中移动、蚂蚁、顺丰、兴盛优选技术专家,带你了解架构稳定性保障

Why should Li Shufu personally take charge of building mobile phones?
随机推荐
Jielizhi obtains the currently used dial information [chapter]
Spark accumulator and broadcast variables and beginners of sparksql
Wechat applet obtains mobile number
Why should Li Shufu personally take charge of building mobile phones?
EasyCVR平台通过接口编辑通道出现报错“ID不能为空”,是什么原因?
OpenEuler 会长久吗
C # nanoframework lighting and key esp32
高精度运算
TCP packet sticking problem
Jerry's access to additional information on the dial [article]
Shell input a string of numbers to determine whether it is a mobile phone number
OpenCV中如何使用滚动条动态调整参数
微信小程序中给event对象传递数据
Alibaba brand data bank: introduction to the most complete data bank
Summary of Android interview questions of Dachang in 2022 (II) (including answers)
What is the reason why the video cannot be played normally after the easycvr access device turns on the audio?
Fleet tutorial 13 basic introduction to listview's most commonly used scroll controls (tutorial includes source code)
The art of Engineering
Getting started with pytest ----- allow generate report
QT中Model-View-Delegate委托代理机制用法介绍