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 题解
第一次写博客 ,请多指教! 翻了翻前面的题解发现都是用树状数组来做,这里更新一个 线段树+离散化的做法: 其实这道题是没有必要用线段树的,树状数组就能够解决.但是个人感觉把线段树用熟了会比树状数组更有 ...
随机推荐
- 痞子衡嵌入式:语音处理工具pzh-speech诞生记(2)- 界面构建(wxFormBuilder3.8.0)
大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是语音处理工具pzh-py-speech诞生之界面构建. 之前痞子衡设计过一个串口调试助手pzh-py-com,也专门写过一篇关于其界面构 ...
- 微软的github 上面 有 Docker.DotNet 嗯 作为 菜 只有欣赏的额
.NET Client for Docker Remote API step one 需要下载的 猛戳 Docker.DotNet
- typescript step by step
如果有本 typescript的书 这个名字不错 啊 step one
- widows 10 下解决在npm install python 环境报错的问题
1.使用管理员打开cmd 2.安装 node-gyp; gyp是一种根据c++源代码编译的工具,node-gyp就是为node编译c++扩展的时候使用的编译工具. npm install -g nod ...
- Linux 6种日志查看方法,不会看日志会被鄙视的
作为一名后端程序员,和Linux打交道的地方很多,不会看Linux日志,非常容易受到来自同事和面试官的嘲讽,所以掌握一种或者几种查看日志的方法非常重要. Linux查看日志的命令有多种: tail.c ...
- asp.net core 3.x 身份验证-2启动阶段的配置
注册服务.配置选项.添加身份验证方案 在Startup.ConfigureServices执行services.AddAuthentication() 注册如下服务(便于理解省略了部分辅助服务): s ...
- C++输出中文字符
注:本文转载自互联网,感谢作者整理! 1. cout 场景1: 在源文件中定义 const char* str = "中文" 在 VC++ 编译器上,由于Windows环境用 ...
- two measures precision and recall of classification
In pattern recognition and information retrievial with binary classification , there are some measur ...
- 2018icpc徐州网络赛-H Ryuji doesn't want to study(线段树)
题意: 有n个数的一个数组a,有两个操作: 1 l r:查询区间[l,r]内$a[l]*(r-l+1)+a[l+1]*(r-l)+a[l+2]*(r-l-1)+\cdots+a[r-1]*2+a[r] ...
- 深入JVM垃圾回收机制,值得你收藏
JVM可以说是为了Java开发人员屏蔽了很多复杂性,让Java开发的变的更加简单,让开发人员更加关注业务而不必关心底层技术细节,这些复杂性包括内存管理,垃圾回收,跨平台等,今天我们主要看看JVM的垃圾 ...