成段更新+离散化才能过,数据好强。。

单点更新挂在了test27,下次做到成段更新再来做!


/*
期望=存活概率*点权值/100
ans=sum(期望)
离散化树木权值,数轴统计累加可能倒下的树木概率(直接加权值即可)
线段树单点,sum[rt]维护在这个区间中所有蘑菇的存活期望值
*/
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
#define maxn 100005
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ll long long
using namespace std;
struct Tree{
int pos,h,pl,pr;//坐标,高度,左概率,右概率
}tree[maxn];
struct Mushroom{
int pos,w;//蘑菇坐标,蘑菇权值
}mushroom[maxn];
int axis[maxn<<],cnt,tot;
double poss[maxn<<];//排序后的坐标点,数轴[1,maxn<<3]上存活概率
double sum[maxn<<];
void build(int l,int r,int rt){
sum[rt]=;
if(l==r)
return;
int m=l+r>>;
build(lson);
build(rson);
}
inline pushup(int rt){
sum[rt]=sum[rt<<]+sum[rt<<|];
}
void update(int pos,double val,int l,int r,int rt){
sum[rt]+=val;
if(l==r) return;
int m=l+r>>;
if(pos<=m) update(pos,val,lson);
else update(pos,val,rson);
}
int main(){
int n,m;
scanf("%d%d",&n,&m);
cnt=;
for(int i=;i<=n;i++){
scanf("%d%d%d%d",&tree[i].pos,&tree[i].h,&tree[i].pl,&tree[i].pr);
axis[cnt++]=tree[i].pos;
axis[cnt++]=tree[i].pos-tree[i].h;
axis[cnt++]=tree[i].pos+tree[i].h;
}
for(int i=;i<=m;i++){
scanf("%d%d",&mushroom[i].pos,&mushroom[i].w);
axis[cnt++]=mushroom[i].pos;
} sort(axis,axis+cnt);
int tot=unique(axis,axis+cnt)-axis;//离散化
for(int i=;i<=tot;i++)//一开始所有的坐标上存活概率都是1
poss[i]=;
//每个点找坐标logn,打标记最多n,复杂度O(n*n)
for(int i=;i<=n;i++){
int pos=lower_bound(axis,axis+tot,tree[i].pos)-axis+;
int posl=lower_bound(axis,axis+tot,tree[i].pos-tree[i].h)-axis+;
int posr=lower_bound(axis,axis+tot,tree[i].pos+tree[i].h)-axis+;
for(int j=posl;j<pos;j++)//倒在左区间的概率
poss[j]*=-(double)tree[i].pl/;
for(int j=pos+;j<=posr;j++)//倒在右区间的概率
poss[j]*=-(double)tree[i].pr/;
}
//至此统计完概率,开始建立线段树
build(,tot,);
for(int i=;i<=m;i++){
int pos=lower_bound(axis,axis+tot,mushroom[i].pos)-axis+;
update(pos,mushroom[i].w*poss[pos],,tot,);//把权值*期望更新到线段树中
}
printf("%.4lf\n",sum[]); return ;
}

 

codeforce 139E的更多相关文章

  1. Codeforce - Street Lamps

    Bahosain is walking in a street of N blocks. Each block is either empty or has one lamp. If there is ...

  2. Codeforce Round #216 Div2

    e,还是写一下这次的codeforce吧...庆祝这个月的开始,看自己有能,b到什么样! cf的第二题,脑抽的交了错两次后过了pretest然后system的挂了..脑子里还有自己要挂的感觉,果然回头 ...

  3. Codeforce 水题报告(2)

    又水了一发Codeforce ,这次继续发发题解顺便给自己PKUSC攒攒人品吧 CodeForces 438C:The Child and Polygon: 描述:给出一个多边形,求三角剖分的方案数( ...

  4. codeforce 375_2_b_c

    codeforce 375_2 标签: 水题 好久没有打代码,竟然一场比赛两次卡在边界条件上....跪 b.题意很简单...纯模拟就可以了,开始忘记了当字符串结束的时候也要更新两个值,所以就错了 #i ...

  5. codeforce 367dev2_c dp

    codeforce 367dev2_c dp 标签: dp 题意: 你可以通过反转任意字符串,使得所给的所有字符串排列顺序为字典序,每次反转都有一定的代价,问你最小的代价 题解:水水的dp...仔细想 ...

  6. 三维dp&codeforce 369_2_C

    三维dp&codeforce 369_2_C 标签: dp codeforce 369_2_C 题意: 一排树,初始的时候有的有颜色,有的没有颜色,现在给没有颜色的树染色,给出n课树,用m种燃 ...

  7. 强连通分量&hdu_1269&Codeforce 369D

    强连通分量 标签: 图论 算法介绍 还记得割点割边算法吗.回顾一下,tarjan算法,dfs过程中记录当前点的时间戳,并通过它的子节点的low值更新它的low,low值是这个点不通过它的父亲节点最远可 ...

  8. 【树状数组】区间出现偶数次数的异或和(区间不同数的异或和)@ codeforce 703 D

    [树状数组]区间出现偶数次数的异或和(区间不同数的异或和)@ codeforce 703 D PROBLEM 题目描述 初始给定n个卡片拍成一排,其中第i个卡片上的数为x[i]. 有q个询问,每次询问 ...

  9. 解题报告:codeforce 7C Line

    codeforce 7C C. Line time limit per test1 second memory limit per test256 megabytes A line on the pl ...

随机推荐

  1. Django 2.0.3 使用笔记

    运行环境: Python 3.5.2 Django 2.0.3 Django Admin中model显示为中文 定义model时,定义一个Meta对象,设置需要显示的中文名称.verbose_name ...

  2. libevent-2.0.so.5 (安装MEMCACHED问题)

    今天安装memcache启动服务时出现 error while loading shared libraries: libevent-2.0.so.5: cannot open shared obje ...

  3. Python基础【day03】:集合入门(三)

    本节内容 1.集合常用方法总结2.定义3.关系测试 集合是无序的,天生不重复的数据组合,它的作用如下: 去重,即:把一个列表变成集合,就去重了 关系测试,即:测试两组集合的交集.并集和差集等 一.集合 ...

  4. python---自定义分页类

    # coding:utf8 # __author: Administrator # date: 2018/3/7 0007 # /usr/bin/env python import tornado.w ...

  5. js的各种验证

    验证手机号格式是否正确 // 判断是否为手机号 isPoneAvailable: function (pone) { var myreg = /^[1][3,4,5,7,8][0-9]{9}$/; i ...

  6. C++面试集锦( 面试被问到的问题 )

    1. C 和 C++ 区别 2. const 有什么用途     主要有三点: 1:定义只读变量,即常量 2:修饰函数的参数和函数的返回值 3: 修饰函数的定义体,这里的函数为类的成员函数,被cons ...

  7. 在IIS上启用Gzip压缩(HTTP压缩)

    一.摘要 本文总结了如何为使用IIS托管的网站启用Gzip压缩, 从而减少网页网络传输大小, 提高用户显示页面的速度. 二.前言. 本文的知识点是从互联网收集整理, 主要来源于中文wiki.  使用Y ...

  8. java基础面试题常出现(一)

    1.”==“和equals方法的区别? 1.   ==操作符,对于基本数据类型变量,比较的是两个值是否相等,而对于引用类型,比较的是引用的内存的首地址,即引用同一个对象.1 Obeject的equal ...

  9. Linux 4.10.8 根文件系统制作(一)---环境搭建

    一.工具 制作工具为busybox 下载地址:https://busybox.net/ 解压: 二.制作文件系统 进入目录,执行make menuconfig: 2.1 busybox setting ...

  10. sqlite limit offset

    limit 0,20 表示从第1条开始取20条数据 limit 20 offset 2  表示从第2条开始取出20条数据