当前位置:网站首页>Educational codeforces round 126 (rated for Div. 2) f.teleporters (two sets and two points)
Educational codeforces round 126 (rated for Div. 2) f.teleporters (two sets and two points)
2022-07-28 17:10:00 【Code92007】
subject
The positive axis of the number axis has n(n<=2e5) On the hour ,
From the point of i To j The cost of is the square of the difference between the two , Given a 
You need to get from 0 To
, The cost does not exceed
, Ask at least how many whole points to add , time limit 7 second
Source of ideas
Liangshen
Answer key
Before you think about the correct solution, you might as well consider how to do it with simplicity , Then consider how to optimize ,dp such , Line segment tree && The same goes for two points
n There are n Segment length distance , Consider giving the i Add a A little bit , And to the first i Add a+1 A little bit ,
Compare the two , Add a dot , There is a value corresponding to the cost reduction , Write it down as x,
If the priority queue can be maintained violently , Obviously every time I look x Maximum value ,
hold a out , Total cost minus x, And then a+1 Throw it back ,
Then you can consider the process of dichotomy , Bisect all segments , The value of incremental cost reduction >x The smallest that has been used up x,
Find out the x after , How many points are actually inserted into each line segment L, That makes it possible to add L Points minus plus L+1 The increment of points shall not exceed x, adopt L Calculate the contribution to the sum of costs
be equal to x The increment of may have used a part , Here is to consider x The increment of ,
At this time, it must be less than m, So you can consider going back delta/x A little bit ,
Because it is x The emergence of makes from >m become <=m, therefore x It must be enough , Direct division
Experience

Not complicated , But the greater than sign and greater than or equal sign have been adjusted for a long time , Lead to E There is no time to write after the title
Liangshen : Can you really write binary search ? I : Obviously not. .
Code
#include<bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f,N=2e5+10;
#define dbg1(x) cerr<<(#x)<<" "<<(x)<<" ";
#define dbg2(x) cerr<<(#x)<<" "<<(x)<<" "<<endl;
typedef long long ll;
const ll mx=1e18;
int n,a[N];
ll b[N],m,ans,tot1,sum1;
ll sq(ll x){
return x*x;
}
ll cal(ll x,ll a){// Long for x Divide into m The cost of the segment
if(a>x)return x;
ll v=x%a,r=x/a;
ll ans=v*sq(r+1)+(a-v)*sq(r);
return ans;
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i){
scanf("%d",&a[i]);
b[i]=a[i]-a[i-1];
}
scanf("%lld",&m);
ll l=0,r=mx;
while(l<=r){
ll mid=(l+r)/2,sum=0;
for(int i=1;i<=n;++i){
ll L=1,R=b[i];
while(L<=R){
ll M=(L+R)/2;
if(cal(b[i],M)-cal(b[i],M+1)>=mid){
L=M+1;
}
else{
R=M-1;
}
}
sum+=cal(b[i],L);
}
if(sum<=m){
l=mid+1;
}
else{
r=mid-1;
}
}
for(int i=1;i<=n;++i){
ll L=1,R=b[i];
while(L<=R){
ll M=(L+R)/2;
if(cal(b[i],M)-cal(b[i],M+1)>=r){
L=M+1;
}
else{
R=M-1;
}
}
sum1+=cal(b[i],L);
tot1+=L-1;
}
printf("%lld\n",tot1-(m-sum1)/r);
return 0;
}边栏推荐
- Rsync 服务部署与参数详解
- 2022牛客多校第二场CDE
- Alibaba cloud MSE supports go language traffic protection
- [deep learning]: day 8 of pytorch introduction to project practice: weight decline (including source code)
- mysql 最大建议行数2000w,靠谱吗?
- 3D modeling tool Archicad 26 newly released
- 【深度学习】:《PyTorch入门到项目实战》第九天:Dropout实现(含源码)
- PostgreSQL每周新闻—2022年7月20日
- 在AD中添加差分对及连线
- Ugui learning notes (VI) get the information of the clicked UI
猜你喜欢

RE14: reading paper illsi interpretable low resource legal decision making

Ugui learning notes (II) Scrollview related

HTAP comes at a price

PostgreSQL weekly news - July 20, 2022

Unity shader realizes water wave effect with noise texture

Comprehensively design an oppe homepage -- after sales service of the page

Re10:读论文 Are we really making much progress? Revisiting, benchmarking, and refining heterogeneous gr

数据库故障容错之系统时钟故障

综合设计一个OPPE主页--页面服务部分

【深度学习】:《PyTorch入门到项目实战》第七天之模型评估和选择(上):欠拟合和过拟合(含源码)
随机推荐
Hikvision responded to the impact of the 'US ban': there are options for the components currently used
Programmers from entry to roast!!!!
Unity3d simple implementation of water surface shader
华为Mate 40系列曝光:大曲率双曲面屏,5nm麒麟1020处理器!还将有天玑1000+的版本
打造自组/安全/可控的LoRa网!Semtech首度回应“工信部新规”影响
2020Q2全球平板市场出货大涨26.1%:华为排名第三,联想增幅最大!
Exercise note 5 (square of ordered array)
Re13:读论文 Gender and Racial Stereotype Detection in Legal Opinion Word Embeddings
记录ceph两个rbd删除不了的处理过程
RE14: reading paper illsi interpretable low resource legal decision making
综合设计一个OPPE主页--页面服务部分
PostgreSQL weekly news - July 20, 2022
System clock failure of database fault tolerance
Leetcode647. Palindrome substring
数据库故障容错之系统时钟故障
Unity shader procedural texture
传英伟达已与软银展开会谈,将出价超过320亿美元收购Arm
Some opinions on bug handling
SUSE Ceph 增加节点、减少节点、 删除OSD磁盘等操作 – Storage6
leetcode70假设你正在爬楼梯。需要 n 阶你才能到达楼顶。每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢?