这次比赛从名字就可以看出非常水,然鹅因为第一次打codeforces不太熟悉操作只来的及做签到题(还错了一次)

A,B,C都是签到题考点思维就不写了

D题

https://codeforces.ml/problemset/problem/1311/D

题目大意是:有t组数据每组数据给你三个数,a,b,c每次一个数加一或

者减一都算一次操作(不能为变负数),问最小的操作次数构造出A,

B,C使b%a==0,c%b==0。

t<1000,a,b,c<1e4 时限2s

首先想到是找b的倍数与a,c最近的数再直接加减

再一看时限两秒。。。果断暴力

然后就枚举这样的数对A,B,C,答案就是其a,b,c的差的最小值

#代码后面有时间再补

E题

https://codeforces.ml/contest/1311/problem/E

奈何本人没文化,题目没怎么懂,日后有时间再补(flag)

接下来才是重头戏


F题

https://codeforces.ml/problemset/problem/1311/F

题目大意:给你n(<2e5)个点a1,a2,...,an在同一个数轴上,保证坐标不会重复, 每个点有一个固定的速度(-1e8到1e8),对某一个t时刻,某两个点距离最小,输出这些最小值之和(min d(i,j)i<j之和)

容易先想到将a按坐标排序,xi<xj,vi<vj那d(i,j)肯定不会减小则min d(i,j)=xj-xi,如果vi>vj 则min d(i,j)=0


暴力n^2代码很简单

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=2e5+5;
int n;
long long tot;
struct node
{
long long x,v;
}a[N];
bool cmp(node x,node y)
{
return x.x<y.x;
}
int main()
{ scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%lld",&a[i].x);
for(int i=1;i<=n;i++)
scanf("%lld",&a[i].v);
sort(a+1,a+n+1,cmp);
for(int i=2;i<=n;i++)
{
for(int j=1;j<i;j++)
{
if(a[i].v>=a[j].v)
{
tot+=a[i].x-a[j].x;
}
}
}
printf("%lld",tot);
return 0;
}

  

因为ans+=xi⋅cnt−sum可以将每次枚举看成从当前新建的数组中添加一个元素,因为从小到大遍历的所以速度小于i而x大于i的一定还没有被加入新建的数组所以此想法可以算出满足条件的num和tot。

具体做法是新建两个数组q,p开始都为空,第一个数组q[i]代表a[1~i].v中速度为q的a[1~i].x(坐标)的和,第二个数组p[i]代表速度为p[i]的个数而这可以用树状数组优化。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=2e5+5;
int n,m,pos,v[N];
long long tot,s[N][2];
struct node
{
long long x,v;
}a[N];
bool cmp(node x,node y)
{
return x.x<y.x;
}
int lowbit(int x)
{
return x&(-x);
}
void update(int x,int val)//更新数组
{
while(x<=n)
{
s[x][0]++;
s[x][1]+=val;
x+=lowbit(x);//从x往上更新所有q,p数组有关a[x]的值
}
}
long long getsum(int x,int flag)//获取数组1~x的和
{
long long res=0;
while(x)
{
res+=s[x][flag];
x-=lowbit(x); //从x往下加故是减号
}
return res;
}
int main()
{ scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%lld",&a[i].x);
for(int i=1;i<=n;i++)
{
scanf("%lld",&a[i].v);
v[i]=a[i].v;
}
sort(a+1,a+n+1,cmp);
sort(v+1,v+n+1);
m=unique(v+1,v+n+1)-v-1;
for(int i=1;i<=n;i++)
{
pos=lower_bound(v+1,v+m+1,a[i].v)-v;
tot+=getsum(pos,0)*a[i].x-getsum(pos,1);//s[][0]代表p[i],s[][1]代表q[i]
update(pos,a[i].x);
}
printf("%lld",tot);
return 0;
}

  

CODEFORCES ROUND#624 DIV3的更多相关文章

  1. 【赛时总结】◇赛时·V◇ Codeforces Round #486 Div3

    ◇赛时·V◇ Codeforces Round #486 Div3 又是一场历史悠久的比赛,老师拉着我回来考古了……为了不抢了后面一些同学的排名,我没有做A题 ◆ 题目&解析 [B题]Subs ...

  2. Codeforces Round #624 (Div. 3)(题解)

    Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...

  3. CodeForces Round #527 (Div3) B. Teams Forming

    http://codeforces.com/contest/1092/problem/B There are nn students in a university. The number of st ...

  4. CodeForces Round #527 (Div3) D2. Great Vova Wall (Version 2)

    http://codeforces.com/contest/1092/problem/D2 Vova's family is building the Great Vova Wall (named b ...

  5. CodeForces Round #527 (Div3) D1. Great Vova Wall (Version 1)

    http://codeforces.com/contest/1092/problem/D1 Vova's family is building the Great Vova Wall (named b ...

  6. CodeForces Round #527 (Div3) C. Prefixes and Suffixes

    http://codeforces.com/contest/1092/problem/C Ivan wants to play a game with you. He picked some stri ...

  7. CodeForces Round #527 (Div3) A. Uniform String

    http://codeforces.com/contest/1092/problem/A You are given two integers nn and kk. Your task is to c ...

  8. CodeForces Round#480 div3 第2场

    这次div3比上次多一道, 也加了半小时, 说区分不出1600以上的水平.(我也不清楚). A. Remove Duplicates 题意:给你一个数组,删除这个数组中相同的元素, 并且保留右边的元素 ...

  9. Codeforces Round #624 (Div. 3) F. Moving Points 题解

    第一次写博客 ,请多指教! 翻了翻前面的题解发现都是用树状数组来做,这里更新一个 线段树+离散化的做法: 其实这道题是没有必要用线段树的,树状数组就能够解决.但是个人感觉把线段树用熟了会比树状数组更有 ...

随机推荐

  1. python算法学习总结

    数据结构一维: 基础:数组array(string),链表Linked List 高级:栈stack,队列queue,双端队列deque,集合set,映射map(hash or map), etc二维 ...

  2. 根据指定路由生成URL |Generating a URL from a Specific Route | 在视图中生成输出URL|高级路由特性

    后面Length=5 是怎么出现的?

  3. GP工作室-团队项目Beta冲刺

    GP工作室-团队项目Beta冲刺 这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/GeographicInformationScience/ 这个作业要求 ...

  4. 创建dynamics CRM client-side (十) - 用JS来获取form type

    用户可以用以下代码来获取 form type 更多的信息可以查阅https://docs.microsoft.com/en-us/powerapps/developer/model-driven-ap ...

  5. 图像处理:AlphaBlend混合两张图片

    使用vs2017新建一个项目 混合A,B两张图的基础算法: outColor = srcColor * srcAlpha + destColor * (1 - srcAlpha) 输出颜色 = 源颜色 ...

  6. linux-->yii2报yii\db\Exception错

    linux 中yii2 yii\db\Exception报错 报错显示:Database Exception – yii\db\Exception SQLSTATE[HY000] [2002] No ...

  7. DataTable 相关

    1.对表的初始化 //创建表 DataTable table = new DataTable(); //添加列 table.Columns.Add("ID", typeof(Int ...

  8. css-box-shadowing

    box-shadow: h-shadow v-shadow blur spread color inset; 注释:box-shadow 向框添加一个或多个阴影.该属性是由逗号分隔的阴影列表,每个阴影 ...

  9. 如何用Flink把数据sink到kafka多个(成百上千)topic中

    需求与场景 上游某业务数据量特别大,进入到kafka一个topic中(当然了这个topic的partition数必然多,有人肯定疑问为什么非要把如此庞大的数据写入到1个topic里,历史留下的问题,现 ...

  10. ccf

    import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; public class MST { pu ...