当前位置:网站首页>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;
}边栏推荐
- Outline and principle of structured design -- modularization
- 【深度学习】:《PyTorch入门到项目实战》第一天:数据操作和自动求导
- Games101 assignment04 job 04
- Alibaba cloud - Wulin headlines - site building expert competition
- 海康威视回应'美国禁令'影响:目前所使用的元器件都有备选
- Leetcode70 suppose you are climbing stairs. You need n steps to reach the roof. You can climb one or two steps at a time. How many different ways can you climb to the roof?
- Egg (19): use egg redis performance optimization to cache data and improve response efficiency
- [deep learning]: day 9 of pytorch introduction to project practice: dropout implementation (including source code)
- 【深度学习】:《PyTorch入门到项目实战》第四天:从0到1实现logistic回归(附源码)
- Record the processing process of CEPH two RBDS that cannot be deleted
猜你喜欢

Unity shader screen post-processing

Unity shader procedural texture

Re13:读论文 Gender and Racial Stereotype Detection in Legal Opinion Word Embeddings

22年多校第三场(F的证明

ERROR: transport library not found: dt_ socket

阿里云 MSE 支持 Go 语言流量防护

Ugui learning notes (II) Scrollview related

浏览器解码过程分析

The maximum recommended number of rows for MySQL is 2000W. Is it reliable?

总数据量超万亿行,玉溪卷烟厂通过正确选择时序数据库轻松应对
随机推荐
Android Development - set cache
Given positive integers n and m, both between 1 and 10 ^ 9, n < = m, find out how many numbers have even digits between them (including N and m)
Realize the reset function of steering wheel UI with touch rotation and finger departure in unity
Unity shader realizes mirror effect with rendered texture
Summary of kubenertes 1.16 cluster deployment problems
浏览器解码过程分析
Unity shader uses rendered texture to achieve glass effect
Ugui learning notes (I) rendering level
[deep learning]: day 8 of pytorch introduction to project practice: weight decline (including source code)
MySQL 5.7 and sqlyogv12 installation and use cracking and common commands
关于Bug处理的一些看法
Detailed steps for setting up SUSE storage6 environment – win10 + VMware Workstation
Programmers from entry to roast!!!!
技术分享 | 误删表以及表中数据,该如何恢复?
Unity3d simple implementation of water surface shader
How to use fail2ban to protect WordPress login page
【深度学习】:《PyTorch入门到项目实战》第六天:多层感知机(含代码)
Semtech launched Lora edge, a geolocation solution for the Internet of things, and the first chip lr1110 is now on the market
2022牛客多校第二场CDE
综合设计一个OPPE主页--页面的售后服务