CODEFORCES ROUND#624 DIV3
这次比赛从名字就可以看出非常水,然鹅因为第一次打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的更多相关文章
- 【赛时总结】◇赛时·V◇ Codeforces Round #486 Div3
◇赛时·V◇ Codeforces Round #486 Div3 又是一场历史悠久的比赛,老师拉着我回来考古了……为了不抢了后面一些同学的排名,我没有做A题 ◆ 题目&解析 [B题]Subs ...
- Codeforces Round #624 (Div. 3)(题解)
Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- CodeForces Round#480 div3 第2场
这次div3比上次多一道, 也加了半小时, 说区分不出1600以上的水平.(我也不清楚). A. Remove Duplicates 题意:给你一个数组,删除这个数组中相同的元素, 并且保留右边的元素 ...
- Codeforces Round #624 (Div. 3) F. Moving Points 题解
第一次写博客 ,请多指教! 翻了翻前面的题解发现都是用树状数组来做,这里更新一个 线段树+离散化的做法: 其实这道题是没有必要用线段树的,树状数组就能够解决.但是个人感觉把线段树用熟了会比树状数组更有 ...
随机推荐
- c++ 文件的简单操作
文件的读取操作 在程序设计中,文件常用的操作不外乎--打开.读.写.流指针操作.关闭.我日常中使用的比较多,但从来 没有细细总结今天就总结下具体的用法. 相关概念 计算机上的文件其实是数据的集合,对文 ...
- Easy C 编程 in Linux
入坑Ubuntu有4,5天了,当时各种不习惯,但现在渐渐喜欢上了这种简单大方的显示界面和快速高效的命令行模式,各种没有的功能也都有网页版,非常不错呢. 现在最让我感到神奇之处,便是Linux的C编程是 ...
- [集训]Evocation
题意 一颗有根树,每个点有黑白两种颜色和阀值ai,若它的子树中(不包括自己)的黑色数量大于ai,则产生一点贡献.每次将一个点的颜色取反,求每次修改后的贡献.n,q<=1E5. 思考 树剖后直接分 ...
- BOM DOM 注意事項
setTimeout(js,時間) js处 应该放一个函数 不能放 alert confirm 等 (否则延时会失效) setTimeout() 和 setInterval() 的区别: ...
- SpringCloud与微服务Ⅹ --- SpringCloud Config分布式配置中心
一.SpringCloud Config是什么 分布式系统面临的问题 --- 配置问题 微服务意味着要将单体应用中的业务拆分成一个个子服务,每个服务的粒度相对较小,因此系统中会出现大量的服务.由于每个 ...
- MVC ajaxfileupload 实现无刷新导入或上传功能
直接上代码吧 前台 先引用 ajaxfileupload.js <script src="~/Scripts/ajaxfileupload.js"></scrip ...
- springcloud 依赖版本问题
SpringCloud 版本: 版本名称 版本 Finchley snapshot版 Edgware snapshot版 Dalston SR1 当前最新稳定版本 Camden SR7 稳定版本 Br ...
- qt QSplitter分割窗口
#include <QApplication> #include <QFont> #include <QTextEdit> #include <QSplitt ...
- Ubuntu下python使用pyenv+virtualenv进行版本和包隔离
安装pyenv 参考:https://github.com/pyenv/pyenv git clone https://github.com/pyenv/pyenv.git ~/.pyenv echo ...
- A Hybrid Data Association Framework for Robust Online Multi-Object Tracking(2017 IEEE Transactions on Image Processing)
A Hybrid Data Association Framework for Robust Online Multi-Object Tracking 一种用于鲁棒在线多目标跟踪的混合数据关联框架 摘 ...