Codeforces 138C(区间更新+离散化)
题意:有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(区间更新+离散化)的更多相关文章
- POJ-2528 Mayor's posters (线段树区间更新+离散化)
题目分析:线段树区间更新+离散化 代码如下: # include<iostream> # include<cstdio> # include<queue> # in ...
- POJ 2528 Mayor's posters (线段树区间更新+离散化)
题目链接:http://poj.org/problem?id=2528 给你n块木板,每块木板有起始和终点,按顺序放置,问最终能看到几块木板. 很明显的线段树区间更新问题,每次放置木板就更新区间里的值 ...
- POJ2528 Mayor's posters(线段树&区间更新+离散化)题解
题意:给一个区间,表示这个区间贴了一张海报,后贴的会覆盖前面的,问最后能看到几张海报. 思路: 之前就不会离散化,先讲一下离散化:这里离散化的原理是:先把每个端点值都放到一个数组中并除重+排序,我们就 ...
- POJ2528:Mayor's posters(线段树区间更新+离散化)
Description The citizens of Bytetown, AB, could not stand that the candidates in the mayoral electio ...
- ACM-线段树区间更新+离散化
区间更新与单点更新最大的不同就在于Lazy思想: http://blog.sina.com.cn/s/blog_a2dce6b30101l8bi.html 可以看这篇文章,讲得比较清楚 在具体使用上, ...
- ZOJ 2301 Color the Ball 线段树(区间更新+离散化)
Color the Ball Time Limit: 2 Seconds Memory Limit: 65536 KB There are infinite balls in a line ...
- POJ-2528 Mayor's posters(线段树区间更新+离散化)
http://poj.org/problem?id=2528 https://www.luogu.org/problem/UVA10587 Description The citizens of By ...
- 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 ...
- POJ 2528 Mayor's posters(线段树/区间更新 离散化)
题目链接: 传送门 Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Description The citizens of By ...
随机推荐
- oracle on linux 巡检脚本-部分
#!/bin/sh #ocpyang@126.com #Modified according to the actual situation mysql server IP and username ...
- gomail发送附件
采用github.com/go-gomail/gomail/ 的邮件功能,可以发送附件 以及html文档,下面是其给出的demo,测试通过. package main //cmd: go get go ...
- (转)Tomcat目录结构
首先来了解一下Tomcat5.5的目录结构: /bin:存放windows或Linux平台上启动和关闭Tomcat的脚本文件 /conf:存放Tomcat服务器的各种全局配置文件,其中包括server ...
- HDU 4869 Turn the pokers(思维+组合公式+高速幂)
pid=4869" target="_blank">Turn the pokers 大意:给出n次操作,给出m个扑克.然后给出n个操作的个数a[i],每一个a[i] ...
- C# foreach 循环遍历数组
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...
- Flask项目之手机端租房网站的实战开发(十二)
说明:该篇博客是博主一字一码编写的,实属不易,请尊重原创,谢谢大家! 接着上一篇博客继续往下写 :https://blog.csdn.net/qq_41782425/article/details/8 ...
- error LNK2001: unresolved external symbol "public: virtual
1) Mine solution : project-setting :static lib to shared dll .then ok. 找不到secondchar的定义, 你是否没有把包含sec ...
- 图解String类型的不可变性及其原因
1.String的不可变性 String s="abcd": 上面的语句定义了一个字符串变量s.该变量指向字符串"abcd",当初始化变量s时,会在堆中为s非配 ...
- Android 撕衣服(刮刮乐游戏)
项目简单介绍: 该项目为撕衣服,相似刮刮乐游戏 具体介绍: 用户启动项目后.载入一张图片,当用户点击图片的时候,点击的一片区域就会消失.从而显示出在这张图片以下的图片 这个小游戏相似与刮奖一样,刮开涂 ...
- node的express参数获取
1.express中的不定向路由参数的获取 如: app.get('/profile/:id', function(req, res) { var id=req.params.id res.send( ...