题意:有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. android:giavity和layout_gravity的差别

    android:gravity: 是对该view中内容的限定.比方一个button 上面的text. 你能够设置该text 相对于view的靠左,靠右等位置. android:layout_gravi ...

  2. UVa10397_Connect the Campus(最小生成树)(小白书图论专题)

    解题报告 题目传送门 题意: 使得学校网络互通的最小花费,一些楼的线路已经有了. 思路: 存在的线路当然全都利用那样花费肯定最小,把存在的线路当成花费0,求最小生成树 #include <ios ...

  3. Oracle APEX 4.2公布RESTful Webservice

    Purpose This tutorial covers creating a RESTful Web Service and accessing the Web Service through an ...

  4. android 弹幕评论效果

    纯粹依照自己的想法仿照b站的弹幕写的一个demo,不知道正确的姿势怎么样的. demo下载地址 首先.一条弹幕就是一个textview public abstract class Danmu exte ...

  5. sql简单的语句

    选择:select * from table1 where 范围 插入:insert into table1(field1,field2) values(value1,value2) 删除:delet ...

  6. [BZOJ1645][Usaco2007 Open]City Horizon 城市地平线 线段树

    链接 题意:N个矩形块,交求面积并. 题解 显然对于每个 \(x\),只要求出这个 \(x\) 上面最高的矩形的高度,即最大值 将矩形宽度离散化一下,高度从小到大排序,线段树区间set,然后求和即可 ...

  7. Swagger文档转Word

    Swagger文档转Word 文档   GitHub 地址:https://github.com/JMCuixy/SwaggerToWord/tree/developer 原创作品,转载请注明出处:h ...

  8. golang filepath.Walk遍历指定目录下的所有文件

    package main import ( "fmt" "os" "path/filepath" ) func walkFunc(path ...

  9. 福昕pdf阅读器如何删除所有注释

    然后选中第一个 移动到最后按住shift,选择最后一个, 总之就是选中所有的 然后右键,点击删除即可. 不要忘记保存呦

  10. easy ui 验证

    $('#IdentityCertificate').validatebox({required:true}); $('#memberName').validatebox({required:true} ...