考虑两个质量均为m,速度分别v1、v2的小球发生完全弹性碰撞的影响:

由动能守恒得:

$\frac{1}{2}mv_1^2+\frac{1}{2}mv_2^2=\frac{1}{2}mv_1'^2+\frac{1}{2}mv_2'^2$
$v_1^2+v_2^2=v_1'^2+v_2'^2$

由动量守恒得:

$mv_1+mv_2=mv_1'+mv_2'$
$v_1+v_2=v_1'+v_2'$
$v_1^2+v_2^2+2v_1v_2=v_1'^2+v_2'^2+2v_1'v_2'$

所以

$v_1v_2=v_1'v_2'$
$v_1'=v_2$
$v_2'=v_1$

结论:两个质量相同的小球发生完全弹性碰撞后交换速度。

由于询问的是第k小的速率,并没有要求是哪个小球,所以可以视为小球并没有发生碰撞,而是直接按原速度穿过去,所以直接计算出每个小球在t时刻的速度就可以了。

现在考虑怎么求速度:

每一时刻加速度$av=C$

而加速度可以看做是速度函数的导数,

设$f(x)$为x时刻的速度,$f(0)=v$,$f(x)f'(x)=C$

解得

$f(x)=\sqrt{2Cx+v^2}$

因为在t时刻,影响最终速度排名的只有初速度v,所以只需要用数据结构维护v的顺序就可以了。

时间复杂度$O((n+q)\log n)$

#include<cstdio>
#include<cmath>
#define N 200010
using namespace std;
typedef long long ll;
const double A=0.8;
int n,c,x,y,z,size[N],son[N][2],val[N],f[N],tot,root,data[N],id[N],cnt;
int ins(int x,int p){
size[x]++;
int b=p>=val[x];
if(!son[x][b]){
son[x][b]=++tot;f[tot]=x;size[tot]=1;
val[tot]=p;
return tot;
}else return ins(son[x][b],p);
}
void dfs(int x){
if(son[x][0])dfs(son[x][0]);
data[++cnt]=val[x];id[cnt]=x;
if(son[x][1])dfs(son[x][1]);
}
int build(int fa,int l,int r){
int mid=(l+r)>>1,x=id[mid];
f[x]=fa;son[x][0]=son[x][1]=0;size[x]=1;
val[x]=data[mid];
if(l==r)return x;
if(l<mid)size[x]+=size[son[x][0]=build(x,l,mid-1)];
if(r>mid)size[x]+=size[son[x][1]=build(x,mid+1,r)];
return x;
}
inline int rebuild(int x){
cnt=0;dfs(x);return build(f[x],1,cnt);
}
inline void insert(int p){
if(!root){root=tot=size[1]=1;val[1]=p;return;}
int x=ins(root,p);
int deep=0;int z=x;while(f[z])z=f[z],deep++;
if(deep<log(tot)/log(1/A))return;
while((double)size[son[x][0]]<A*size[x]&&(double)size[son[x][1]]<A*size[x])x=f[x];
if(!x)return;
if(x==root){root=rebuild(x);return;}
int y=f[x],b=son[y][1]==x,now=rebuild(x);
son[y][b]=now;
}
inline int kth(int k){
int x=root,sum;
while(1){
sum=size[son[x][0]]+1;
if(k==sum)return val[x];
if(k<sum)x=son[x][0];else k-=sum,x=son[x][1];
}
}
inline void read(int&a){
char c;bool f=0;a=0;
while(!((((c=getchar())>='0')&&(c<='9'))||(c=='-')));
if(c!='-')a=c-'0';else f=1;
while(((c=getchar())>='0')&&(c<='9'))(a*=10)+=c-'0';
if(f)a=-a;
}
int main(){
read(n);read(c);
while(n--)read(x),read(y),read(z),insert(x);
read(n);
while(n--){
read(x);
if(x)read(y),read(z),z=kth(z),printf("%.3f\n",sqrt(2*(ll)c*(ll)y+(ll)z*(ll)z));
else read(x),read(y),read(y),insert(x);
}
return 0;
}

  

BZOJ3570 : DZY Loves Physics I的更多相关文章

  1. 【权值分块】bzoj3570 DZY Loves Physics I

    以下部分来自:http://www.cnblogs.com/zhuohan123/p/3726306.html 此证明有误. DZY系列. 这题首先是几个性质: 1.所有球质量相同,碰撞直接交换速度, ...

  2. CF 444C DZY Loves Physics(图论结论题)

    题目链接: 传送门 DZY Loves Chemistry time limit per test1 second     memory limit per test256 megabytes Des ...

  3. cf444A DZY Loves Physics

    A. DZY Loves Physics time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. Codeforces Round #254 (Div. 1) A. DZY Loves Physics 智力题

    A. DZY Loves Physics 题目连接: http://codeforces.com/contest/444/problem/A Description DZY loves Physics ...

  5. CodeForces 444C. DZY Loves Physics(枚举+水题)

    转载请注明出处:http://blog.csdn.net/u012860063/article/details/37509207 题目链接:http://codeforces.com/contest/ ...

  6. Codeforces 444A DZY Loves Physics(图论)

    题目链接:Codeforces 444A DZY Loves Physics 题目大意:给出一张图,图中的每一个节点,每条边都有一个权值.如今有从中挑出一张子图,要求子图联通,而且被选中的随意两点.假 ...

  7. 【Codeforces 444A】DZY Loves Physics

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 两个点的子图他们的"密度"是比所有联通生成子图都要大的 "只要胆子大,遇到什么问题都不怕!" [代码] ...

  8. CF444A DZY Loves Physics【结论】

    题目传送门 话说这道题不分析样例实在是太亏了...结论题啊... 但是话说回来不知道它是结论题的时候会不会想到猜结论呢...毕竟样例一.二都有些特殊. 观察样例发现选中的子图都只有一条边. 于是猜只有 ...

  9. @codeforces - 444A@ DZY Loves Physics

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个 n 点 m 边的图,边有边权,点有点权. 找到一个连通 ...

随机推荐

  1. Vector3.Lerp 插值

    Vector3.Lerp 插值 static function Lerp (from : Vector3, to : Vector3, t : float) : Vector3 Description ...

  2. ZOJ3741 状压DP Eternal Reality

    E - Eternal Reality Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu S ...

  3. poj1094

    Sorting It All Out Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 29539   Accepted: 10 ...

  4. linux文件分割(将大的日志文件分割成小的)

    linux文件分割(将大的日志文件分割成小的) linux下文件分割可以通过split命令来实现,可以指定按行数分割和安大小分割两种模式.Linux下文件合并可以通过cat命令来实现,非常简单. 在L ...

  5. iOS 利用constraint实现2个控件上下的空白是相等的

    说的有点乱,先看个图把 其实这个constrant的目的就是控制两个方形的控件上方和下方的空白大小. 对于每一个方块来说,他们上方和下方的空白是相同的.这种“居中”的设计到处可见.一个控件想实现这种居 ...

  6. php中重写和final关键字的使用

    为什么把重写和final放在一起,原因就是一条:final的意思是不可更改的,也就是说final定义的东西是不可改变的,下面具体来说一下. 来看一段简单的代码: class BaseClass { f ...

  7. cc.game

    概述 使用cc.game单例代替了原有的cc.Application以及cc.AppControl. cc.game是Cocos2d-JS的游戏对象,主要职责包括,配置的读取,引擎的加载,游戏脚本的加 ...

  8. HDU 5317 RGCDQ (数论素筛)

    RGCDQ Time Limit: 3000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit Status ...

  9. HDU1009老鼠的旅行 (贪心算法)

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  10. 转:JavaScript事件冒泡简介及应用

    (本文转载自别处) JavaScript事件冒泡简介及应用   一.什么是事件冒泡 在一个对象上触发某类事件(比如单击onclick事件),如果此对象定义了此事件的处理程序,那么此事件就会调用这个处理 ...