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

单点更新挂在了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. pandas简短介绍

    1.数据结构 维数 名称 描述 1 Series 一维带标签单一数据类型的数组 2 DataFrame 不同数据类型的列 2.十分钟学习pandas 2.1.导入所需模块 import pandas ...

  2. Java跨平台(系统)的主要原理

    Java是可以在系统运行的,主要是Java在执行的时候先通过Java虚拟机JVM,对应不同的操作系统,JVM会采用对应的翻译机制.

  3. JavaScript中对象分类

    js的对象有三大类,内部对象(本地对象和内置对象).宿主对象和自定义对象 一.内部对象 1.本地对象,ECMAScript提供的需要实例化(new)才能使用的对象: Object.Function.A ...

  4. mysql表备份的一种方式

    前提: 最近测试环境shop表经常出现表损坏不能正常查询,通过mysql的修复方法,暂时有效.故做该表的迁移操作. 思路是: 停止数据库的操作 1.备份老表.  2.创建一个结构一样的表. 3.将老表 ...

  5. 用jsch.jar实现SFTP上传下载删除【转】【补】

    java类: 需要引用的jar: jsch-0.1.53.jar 关于jsch有篇文章关于目录的问题写得非常好:http://www.zzzyk.com/show/9f02969327434a6c.h ...

  6. CentOS6.8搭建rabbitmq消息中间件

    参考资料:http://blog.csdn.net/yunfeng482/article/details/72853983 一.rabbitmq简介 MQ全称为Message Queue, 消息队列( ...

  7. WF控制台工作流(1)

    简单使用WF工作流示例: using System; using System.Linq; using System.Activities; using System.Activities.State ...

  8. QDoubleSpinBox浮点型数字调节框

    样式: import sys from PyQt5.QtWidgets import QApplication, QWidget, QDoubleSpinBox class Demo(QWidget) ...

  9. SpringMVC上传文件的三种方式(待整理...)

    参考链接 http://www.cnblogs.com/fjsnail/p/3491033.html

  10. mysql 语句 GROUP_CONCAT

    select * from blog_log;+----+---------------------+-------+--------+| id | time | level | info |+--- ...