当前位置:网站首页>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;
}
边栏推荐
- Compile and build, from the bottom to the top
- 容器里用systemctl运行服务报错:Failed to get D-Bus connection: Operation not permitted(解决方法)
- Why should Li Shufu personally take charge of building mobile phones?
- The solution that flutterweb browser cannot be rolled back after refreshing
- Spark calculation operator and some small details in liunx
- JMeter interface test response data garbled
- Jerry's watch reads the file through the file name [chapter]
- [introduction to MySQL] the first sentence · first time in the "database" Mainland
- Sqoop I have everything you want
- RB157-ASEMI整流桥RB157
猜你喜欢
There is a gap in traditional home decoration. VR panoramic home decoration allows you to experience the completion effect of your new house
Getting started with pytest ----- test case pre post, firmware
kivy教程之在 Kivy 中支持中文以构建跨平台应用程序(教程含源码)
编译原理——预测表C语言实现
OliveTin能在网页上安全运行shell命令(上)
Scratch epidemic isolation and nucleic acid detection Analog Electronics Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022
一体化实时 HTAP 数据库 StoneDB,如何替换 MySQL 并实现近百倍性能提升
Basic configuration and use of spark
历史上的今天:Google 之母出生;同一天诞生的两位图灵奖先驱
ASEMI整流桥DB207的导通时间与参数选择
随机推荐
FlutterWeb瀏覽器刷新後無法回退的解决方案
JMeter interface test response data garbled
What is the reason why the video cannot be played normally after the easycvr access device turns on the audio?
带你穿越古罗马,元宇宙巴士来啦 #Invisible Cities
[introduction to MySQL] third, common data types in MySQL
The integrated real-time HTAP database stonedb, how to replace MySQL and achieve nearly a hundredfold performance improvement
Stealing others' vulnerability reports and selling them into sidelines, and the vulnerability reward platform gives rise to "insiders"
The art of Engineering (2): the transformation from general type to specific type needs to be tested for legitimacy
Binary search strategy
Cool Lehman has a variety of AI digital human images to create a vr virtual exhibition hall with a sense of technology
adb常用命令
Jerry's updated equipment resource document [chapter]
重磅!蚂蚁开源可信隐私计算框架“隐语”,主流技术灵活组装、开发者友好分层设计...
重磅硬核 | 一文聊透对象在 JVM 中的内存布局,以及内存对齐和压缩指针的原理及应用
Optimization of middle alignment of loading style of device player in easycvr electronic map
Olivetin can safely run shell commands on Web pages (Part 1)
The solution that flutterweb browser cannot be rolled back after refreshing
node の SQLite
面试突击62:group by 有哪些注意事项?
Debug and run the first xv6 program