题意:有n棵树在水平线上,给出每棵树的坐标和高度,然后向左倒的概率和向右倒的概率,和为1,然后给出了m个蘑菇的位置,每一个蘑菇都有一个魔法值,假设蘑菇被压死了,也就是在某棵树[a[i] - h[i], a[i]) 或 (a[i], a[i] + h[i]]范围内。魔法值就没有了。仅仅有生存下来的蘑菇才有魔法值,问生存下来的蘑菇的魔法值的期望。

题解:能够看到n和m的范围是1e5。而坐标范围是1e9。所以肯定要离散化,然后更新每一个区间的概率值,单点查询每一个蘑菇所在区间的概率值乘其魔法值。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
const int N = 100005;
int n, m, a[N], h[N], b[N], z[N], c[N << 2];
double tree[N << 4], flag[N << 4], pl[N], pr[N];
map<int, int> mp; void pushdown(int k) {
if (flag[k]) {
tree[k * 2] *= tree[k];
tree[k * 2 + 1] *= tree[k];
flag[k * 2] = flag[k * 2 + 1] = 1;
tree[k] = 1.0;
flag[k] = 0;
}
} void build(int k, int left, int right) {
flag[k] = 0;
tree[k] = 1.0;
if (left != right) {
int mid = (left + right) / 2;
build(k * 2, left, mid);
build(k * 2 + 1, mid + 1, right);
}
} void modify(int k, int left, int right, int l1, int r1, double x) {
if (l1 <= left && right <= r1) {
tree[k] *= x;
flag[k] = 1;
return;
}
pushdown(k);
int mid = (left + right) / 2;
if (l1 <= mid)
modify(k * 2, left, mid, l1, r1, x);
if (r1 > mid)
modify(k * 2 + 1, mid + 1, right, l1, r1, x);
} double query(int k, int left, int right, int pos) {
if (left == right)
return tree[k];
pushdown(k);
int mid = (left + right) / 2;
if (pos <= mid)
return query(k * 2, left, mid, pos);
else
return query(k * 2 + 1, mid + 1, right, pos);
} int main() {
scanf("%d%d", &n, &m);
mp.clear();
int cnt = 0;
for (int i = 1; i <= n; i++) {
scanf("%d%d%lf%lf", &a[i], &h[i], &pl[i], &pr[i]);
pl[i] /= 100.0, pr[i] /= 100.0;
c[++cnt] = a[i];
c[++cnt] = a[i] - h[i];
c[++cnt] = a[i] + h[i];
}
for (int i = 1; i <= m; i++) {
scanf("%d%d", &b[i], &z[i]);
c[++cnt] = b[i];
}
sort(c + 1, c + 1 + cnt);
cnt = unique(c + 1, c + 1 + cnt) - (c + 1);
for (int i = 1; i <= cnt; i++)
mp[c[i]] = i;
build(1, 1, cnt);
for (int i = 1; i <= n; i++) {
modify(1, 1, cnt, mp[a[i] - h[i]], mp[a[i]] - 1, 1.0 - pl[i]);
modify(1, 1, cnt, mp[a[i]] + 1, mp[a[i] + h[i]], 1.0 - pr[i]);
}
double res = 0;
for (int i = 1; i <= m; i++)
res += z[i] * query(1, 1, cnt, mp[b[i]]);
printf("%lf\n", res);
return 0;
}

Codeforces 138C(区间更新+离散化)的更多相关文章

  1. POJ-2528 Mayor's posters (线段树区间更新+离散化)

    题目分析:线段树区间更新+离散化 代码如下: # include<iostream> # include<cstdio> # include<queue> # in ...

  2. POJ 2528 Mayor's posters (线段树区间更新+离散化)

    题目链接:http://poj.org/problem?id=2528 给你n块木板,每块木板有起始和终点,按顺序放置,问最终能看到几块木板. 很明显的线段树区间更新问题,每次放置木板就更新区间里的值 ...

  3. POJ2528 Mayor's posters(线段树&区间更新+离散化)题解

    题意:给一个区间,表示这个区间贴了一张海报,后贴的会覆盖前面的,问最后能看到几张海报. 思路: 之前就不会离散化,先讲一下离散化:这里离散化的原理是:先把每个端点值都放到一个数组中并除重+排序,我们就 ...

  4. POJ2528:Mayor's posters(线段树区间更新+离散化)

    Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral electio ...

  5. ACM-线段树区间更新+离散化

    区间更新与单点更新最大的不同就在于Lazy思想: http://blog.sina.com.cn/s/blog_a2dce6b30101l8bi.html 可以看这篇文章,讲得比较清楚 在具体使用上, ...

  6. ZOJ 2301 Color the Ball 线段树(区间更新+离散化)

    Color the Ball Time Limit: 2 Seconds      Memory Limit: 65536 KB There are infinite balls in a line ...

  7. POJ-2528 Mayor's posters(线段树区间更新+离散化)

    http://poj.org/problem?id=2528 https://www.luogu.org/problem/UVA10587 Description The citizens of By ...

  8. Educational Codeforces Round 10 D. Nested Segments 【树状数组区间更新 + 离散化 + stl】

    任意门:http://codeforces.com/contest/652/problem/D D. Nested Segments time limit per test 2 seconds mem ...

  9. POJ 2528 Mayor's posters(线段树/区间更新 离散化)

    题目链接: 传送门 Mayor's posters Time Limit: 1000MS     Memory Limit: 65536K Description The citizens of By ...

随机推荐

  1. 【原创】k8s源代码分析-----EndpointController

    转自本人空间 http://user.qzone.qq.com/29185807/blog/1459325937 一.controller manager创建endpointController 代码 ...

  2. Hibernate中编程式事物的简单使用

    一,openSessioin方式开启或者关闭事物 Session session = null; try { session = HibernateUtils.getSession(); sessio ...

  3. ajax同时请求多个服务器?

    这是地址, http://119.29.23.116/info.php 大侠你怎么看 想利用雅黑探针检测服务器的在线状态,但对AJAX多个请求不会操作 header('Access-Control-A ...

  4. widget-移除底部小部件内容

    今天有一个要求,就是在调出手机窗口小部件的时候,让其中的某些小部件不显示.折腾了好久,虽然不知道原理,最终还是实现了屏蔽其中个别小部件的方法.记录下来 要想屏蔽底部小部件的显示,只需要把相关的类跟广播 ...

  5. jquery如何阻止子元素相应mouseout事件

    jquery如何阻止子元素相应mouseout事件:mouseout有一个特点,当鼠标移入子元素的时候,也会触发此事件,但是在实际应用中这个特点往往不是我们想要的,下面就通过代码实例介绍一下如何实现此 ...

  6. scroolspy滚动监听插件

    <nav id="nav" class="navbar navbar-default"> <a href="#" clas ...

  7. Linux下守护进程精析

    什么是守护进程?     守护进程就是通常所说的Daemon进程,它是Linux中的后台服务程序. 它是一个生存期较长的进程,通常独立于终端而且周期性的运行某种须要的任务以及有时候会等待一些将会发生的 ...

  8. Python 极简教程(九)元组 tuple

    元组(tuple)是 Python 中的一种序列.和列表类似,但是元组不可变. 也就是说元组一旦声明后,值就不能再改变.我们先来看看元组的样式: >>> t = () # 空元组 & ...

  9. MyCat中间件:读写分离(转)

    利用MyCat中间件实现读写分离 需要两步: 1.搭建MySQL主从复制环境 2.配置MyCat读写分离策略 一.搭建MySQL主从环境 参考上一篇博文:MySQL系列之七:主从复制 二.配置MyCa ...

  10. debian 9 安装后需做的几件事

    debian 9 安装后需做的几件事 安装环境:X86 >> Debian 9 Linux/GNU apt源更新 注意连上有线网络 刚安装好的debian系统中,/etc/apt/sour ...