【权值分块】bzoj3570 DZY Loves Physics I
以下部分来自:http://www.cnblogs.com/zhuohan123/p/3726306.html
此证明有误。
DZY系列。
这题首先是几个性质:
1.所有球质量相同,碰撞直接交换速度,而球又没有编号,那么就可以直接视作两个球没有碰撞。
2.所有的方向、初始位置都没有任何用处。
然后就是速度的问题了,根据题设
vt=√(2·C·t+v02)
那么T时刻的速度vT的相对大小就直接由v0决定了,我们只需要找到第k小的v0,直接输出答案即可。
现在问题在于:支持插入,查询全局K大值。
平衡树显然可做,但是 权值线段树/权值树状数组 不是更快吗?
但是 权值分块 竟然更快呢?
可能是因为其极小的常数 以及 插入时O(1) 的复杂度吧。
#include<cstdio>
#include<cmath>
using namespace std;
#define max(a,b) (((a)>(b))?(a):(b))
int n,K,V,v[],m,b[],LIMIT,sz,sum,sumv[],l[],r[],num[];
bool op;
double CONST,T;
inline int R(){
char c=;int f=,x;
for(;c<''||c>'';c=getchar())if(c=='-')f=-;
for(x=;c>=''&&c<='';c=getchar())(x*=)+=(c-'');
x*=f; return x;
}
void makeblock()
{
sz=sqrt(LIMIT); if(!sz) sz=; r[]=-;
for(sum=;sum*sz<LIMIT;sum++)
{
l[sum]=r[sum-]+;
r[sum]=sum*sz;
for(int i=l[sum];i<=r[sum];i++) num[i]=sum;
}
l[sum]=r[sum-]+;
r[sum]=LIMIT;
for(int i=l[sum];i<=r[sum];i++) num[i]=sum;
}
void Insert(const int &x){b[x]++; sumv[num[x]]++;}
inline int Kth(const int &x)
{
int cnt=;
for(int i=;;i++)
{
cnt+=sumv[i];
if(cnt>=x)
{
cnt-=sumv[i];
for(int j=l[i];;j++)
{cnt+=b[j]; if(cnt>=x) return j;}
}
}
}
inline double sqr(const double &x){return x*x;}
int main()
{
n=R(); CONST=(double)R();
for(int i=;i<=n;i++)
{
v[i]=R(); R(); R();
LIMIT=max(LIMIT,v[i]);
} makeblock(); m=R();
for(int i=;i<=n;i++) Insert(v[i]);
for(int i=;i<=m;i++)
{
op=R(); if(op)
{
T=(double)R(); K=R();
printf("%.3f\n",sqrt(2.0*CONST*T+sqr((double)Kth(K))));
}
else {V=R(); R(); R(); Insert(V);}
}
return ;
}
【权值分块】bzoj3570 DZY Loves Physics I的更多相关文章
- BZOJ3570 : DZY Loves Physics I
考虑两个质量均为m,速度分别v1.v2的小球发生完全弹性碰撞的影响: 由动能守恒得: $\frac{1}{2}mv_1^2+\frac{1}{2}mv_2^2=\frac{1}{2}mv_1'^2+\ ...
- CF 444C DZY Loves Physics(图论结论题)
题目链接: 传送门 DZY Loves Chemistry time limit per test1 second memory limit per test256 megabytes Des ...
- Codeforces 444A DZY Loves Physics(图论)
题目链接:Codeforces 444A DZY Loves Physics 题目大意:给出一张图,图中的每一个节点,每条边都有一个权值.如今有从中挑出一张子图,要求子图联通,而且被选中的随意两点.假 ...
- Codeforces Round #254 (Div. 1) A. DZY Loves Physics 智力题
A. DZY Loves Physics 题目连接: http://codeforces.com/contest/444/problem/A Description DZY loves Physics ...
- CodeForces 444C. DZY Loves Physics(枚举+水题)
转载请注明出处:http://blog.csdn.net/u012860063/article/details/37509207 题目链接:http://codeforces.com/contest/ ...
- cf444A DZY Loves Physics
A. DZY Loves Physics time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 2019.01.08 bzoj3809: Gty的二逼妹子序列(莫队+权值分块)
传送门 题意:多组询问,问区间[l,r]中权值在[a,b]间的数的种类数. 看了一眼大家应该都知道要莫队了吧. 然后很容易想到用树状数组优化修改和查询做到O(mnlogamax)O(m\sqrt nl ...
- 2018.11.07 NOIP训练 L的鞋子(权值分块+莫队)
传送门 乱搞题. 我直接对权值分块+莫队水过了. 不过调了30min30min30min发现ststst表挂了是真的不想说什么233. 代码
- 【莫队算法】【权值分块】bzoj3920 Yuuna的礼物
[算法一] 暴力. 可以通过第0.1号测试点. 预计得分:20分. [算法二] 经典问题:区间众数,数据范围也不是很大,因此我们可以: ①分块,离散化,预处理出: <1>前i块中x出现的次 ...
随机推荐
- Codeforces Round #350 (Div. 2) D1
D1. Magic Powder - 1 time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 55 (Rated for Div. 2):E. Increasing Frequency
E. Increasing Frequency 题目链接:https://codeforces.com/contest/1082/problem/E 题意: 给出n个数以及一个c,现在可以对一个区间上 ...
- LwIP - raw/callback API、协议栈API(sequential API)、BSD API(或者说 SOCKET API)
1.使用raw/callback API编程,用户编程的方法是向内核注册各种自定义的回调函数,回调函数是与内核实现交换的唯一方式. recv_udp, accept_function, sent_tc ...
- 批量添加公钥给server的bash
Bash 脚本 #/bin/bash adduser vlmonitor mkdir -p /home/vlmonitor/.ssh chown -R vlmonitor.vlmonitor /hom ...
- Sed basic and practice
定义:Sed 是针对数据流的非交谈式编辑器,它在命令行下输入编辑命令并指定文件,然后可以在屏幕上看到编辑命令的输出结果. 好处:Sed 在缓冲区内默认逐行处理数据,所以源文件不会被更改和破坏. 格式: ...
- iebackground+icon图标兼容
<!DOCTYPE > <html> <head> <title>zepto</title> <meta name="nam ...
- 2、Distributed Optimization
一.目录: Distributed dynamic programming (as applied to path-planning problems). Distributed solutions ...
- struts2学习问题(一)
一.struts2 Unknown tag (s:property). 解释:不识别标签 解决:这是sturts2的标签,导入相应的包<%@taglib prefix="s" ...
- 【HDU3853】LOOPS [期望DP]
LOOPS Time Limit: 5 Sec Memory Limit: 64 MB[Submit][Status][Discuss] Description Akemi Homura is a ...
- Hackerrank [World CodeSprint 11] City Construction
传送门:https://www.hackerrank.com/contests/world-codesprint-11/challenges/hackerland [题解] 因为加点每次加1个点1条边 ...