当前位置:网站首页>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;
}边栏推荐
- 做题笔记3(二分查找)
- Make full use of English
- Global mobile communication base station market in 2019: Ericsson, Huawei and Nokia ranked in the top three
- Leetcode647. Palindrome substring
- 记录开发问题
- PostgreSQL每周新闻—2022年7月20日
- 做题笔记5(有序数组的平方)
- Best cow fences solution
- HTAP comes at a price
- Atcoder regular contest 133 d.range XOR (digital dp+ classification discussion)
猜你喜欢

PostgreSQL weekly news - July 20, 2022

【深度学习】:《PyTorch入门到项目实战》第四天:从0到1实现logistic回归(附源码)

Unity shader uses rendered texture to achieve glass effect

概率论与数理统计第一章

Comprehensively design an oppe homepage -- after sales service of the page
![[deep learning]: day 6 of pytorch introduction to project practice: multi-layer perceptron (including code)](/img/19/18d6e94a1e0fa4a75b66cf8cd99595.png)
[deep learning]: day 6 of pytorch introduction to project practice: multi-layer perceptron (including code)

MySQL 5.7 and sqlyogv12 installation and use cracking and common commands

College students participated in six Star Education PHP training and found jobs with salaries far higher than those of their peers

Unity shader global fog effect

ERROR: transport library not found: dt_ socket
随机推荐
Re13:读论文 Gender and Racial Stereotype Detection in Legal Opinion Word Embeddings
【深度学习】:《PyTorch入门到项目实战》第四天:从0到1实现logistic回归(附源码)
[deep learning]: day 5 of pytorch introduction to project practice: realize softmax regression from 0 to 1 (including source code)
parseJson
阿里云 MSE 支持 Go 语言流量防护
做题笔记5(有序数组的平方)
Application of Pegasus d200s UAV and airborne lidar in large-scale DEM construction
Question making note 3 (two point search)
MD5 encryption verification
Technology sharing | MySQL shell customized deployment MySQL instance
技术分享 | 误删表以及表中数据,该如何恢复?
asmlinkage的理解
Ugui learning notes (V) togglegroup makes multiple choice radio boxes
How to use fail2ban to protect WordPress login page
go语言慢速入门——流程控制语句
Record development issues
Record the processing process of CEPH two RBDS that cannot be deleted
Unity shader transparent effect
Leetcode647. Palindrome substring
Alibaba cloud MSE supports go language traffic protection