当前位置:网站首页>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;
}
边栏推荐
- Jerry's updated equipment resource document [chapter]
- BearPi-HM_ Nano development environment
- [rapid environment construction] openharmony 10 minute tutorial (cub pie)
- Easy introduction to SQL (1): addition, deletion, modification and simple query
- Insert dial file of Jerry's watch [chapter]
- Manifest of SAP ui5 framework json
- 微信小程序中给event对象传递数据
- VR全景婚礼,帮助新人记录浪漫且美好的场景
- 面试突击62:group by 有哪些注意事项?
- Jerry's watch reading setting status [chapter]
猜你喜欢

FlutterWeb瀏覽器刷新後無法回退的解决方案

J'aimerais dire quelques mots de plus sur ce problème de communication...

The easycvr platform reports an error "ID cannot be empty" through the interface editing channel. What is the reason?

The solution that flutterweb browser cannot be rolled back after refreshing

Is it meaningful for 8-bit MCU to run RTOS?

BearPi-HM_ Nano development environment

Establishment of graphical monitoring grafana

QT中Model-View-Delegate委托代理机制用法介绍

Pytest learning ----- detailed explanation of the request for interface automation test

I want to say more about this communication failure
随机推荐
分布式不来点网关都说不过去
偷窃他人漏洞报告变卖成副业,漏洞赏金平台出“内鬼”
李書福為何要親自掛帥造手機?
How to output special symbols in shell
sql语句优化,order by desc速度优化
Jerry's setting currently uses the dial. Switch the dial through this function [chapter]
There is a gap in traditional home decoration. VR panoramic home decoration allows you to experience the completion effect of your new house
C语言指针*p++、*(p++)、*++p、*(++p)、(*p)++、++(*p)对比实例
中移动、蚂蚁、顺丰、兴盛优选技术专家,带你了解架构稳定性保障
Principle and usage of extern
The art of Engineering
How to solve the error "press any to exit" when deploying multiple easycvr on one server?
J'aimerais dire quelques mots de plus sur ce problème de communication...
Establishment of graphical monitoring grafana
[getting started with MySQL] fourth, explore operators in MySQL with Kiko
BearPi-HM_ Nano development environment
MySQL stored procedure
Pytest learning ----- detailed explanation of the request for interface automation test
Smart street lamp based on stm32+ Huawei cloud IOT design
SAP UI5 框架的 manifest.json