考虑两个质量均为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. WPF 布局总结

    一.WPF布局原理 WPF窗口只能包含单个元素,为在WPF窗口中放置多个元素,需要放置一个容器,让后在容器中添加其他元素.“理想的”WPF窗口需遵循以下几个原则: 1.不应显示设定元素的尺寸.元素应当 ...

  2. Python socket 详解

    socket()函数用于根据指定的地址族.数据类型和协议来分配一个套接口的描述字及其所用的资源.如果协议protocol未指定(等于0),则使用缺省的连接方式. 对于使用一给定地址族的某一特定套接口, ...

  3. OpenStack 的Nova组件详解

    Open Stack Compute Infrastructure (Nova) Nova是OpenStack云中的计算组织控制器.支持OpenStack云中实例(instances)生命周期的所有活 ...

  4. 【leetcode】Best Time to Buy and Sell Stock II

    Best Time to Buy and Sell Stock II Say you have an array for which the ith element is the price of a ...

  5. Objective-C 和 C++中指针的格式和.方法 和内存分配

    最近在看cocos2d-x,于是打算复习一下C++,在这里简单对比下,留个念想. 先看看oc中指针的用法 @interface ViewController : UIViewController { ...

  6. Java for LeetCode 059 Spiral Matrix II

    Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For ...

  7. SQL 删除存在于A表但是不存在B表中的记录

    目的是是的A表和B表某一个列集合相等 delete from A where tagetColumn not in ( select targetColumn from B)

  8. VS禁止特定警告

    项目右键-属性-配置属性-C/C++-高级-禁用特定警告-填写警告编号例如4996

  9. zabbix 监控客户端数据库 zabbix客户端

    [root@zabbix客户端 zabbix]# grep -v "^$" etc/zabbix_agentd.conf|grep -v "^#" LogFil ...

  10. js伪数组及转换

    什么是伪数组 能通过Array.prototype.slice转换为真正的数组的带有length属性的对象. 这种对象有很多,比较特别的是arguments对象,还有像调用getElementsByT ...