当前位置:网站首页>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;
}
边栏推荐
- Olivetin can safely run shell commands on Web pages (Part 1)
- How to solve the error "press any to exit" when deploying multiple easycvr on one server?
- 重磅硬核 | 一文聊透对象在 JVM 中的内存布局,以及内存对齐和压缩指针的原理及应用
- Insert dial file of Jerry's watch [chapter]
- The difference between parallelism and concurrency
- The art of Engineering (3): do not rely on each other between functions of code robustness
- 78 岁华科教授逐梦 40 载,国产数据库达梦冲刺 IPO
- Getting started with pytest ----- test case pre post, firmware
- 重磅!蚂蚁开源可信隐私计算框架“隐语”,主流技术灵活组装、开发者友好分层设计...
- Pytorch extract middle layer features?
猜你喜欢

BearPi-HM_ Nano development environment

8位MCU跑RTOS有没有意义?

Four processes of program operation

Zen integration nails, bugs, needs, etc. are reminded by nails

Alibaba brand data bank: introduction to the most complete data bank

Open source and safe "song of ice and fire"

历史上的今天:Google 之母出生;同一天诞生的两位图灵奖先驱

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

After entering Alibaba for the interview and returning with a salary of 35K, I summarized an interview question of Alibaba test engineer

RB157-ASEMI整流桥RB157
随机推荐
Manifest of SAP ui5 framework json
Basic configuration and use of spark
Solid principle
《ASP.NET Core 6框架揭秘》样章发布[200页/5章]
The solution that flutterweb browser cannot be rolled back after refreshing
MarkDown语法——更好地写博客
JMeter interface test response data garbled
FMT开源自驾仪 | FMT中间件:一种高实时的分布式日志模块Mlog
微信小程序中给event对象传递数据
C语言指针*p++、*(p++)、*++p、*(++p)、(*p)++、++(*p)对比实例
Spark accumulator and broadcast variables and beginners of sparksql
开源与安全的“冰与火之歌”
The art of Engineering (2): the transformation from general type to specific type needs to be tested for legitimacy
OpenCV中如何使用滚动条动态调整参数
BearPi-HM_ Nano development environment
How to solve the error "press any to exit" when deploying multiple easycvr on one server?
Is it meaningful for 8-bit MCU to run RTOS?
Open source and safe "song of ice and fire"
F200——搭载基于模型设计的国产开源飞控系统无人机
adb常用命令