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 ...
随机推荐
- 数据结构(C实现)------- 单链表
在单链表中,每个结点包括两部分:存放每个数据元素本身信息的数据域和存放其直接后继存储位置的指针域. 单链表结点的类型描写叙述: typedef int ElemType; typedef struct ...
- tokumx的安装和使用
Add the Tokutek package signing key. $ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key ...
- 8lession-基础类型转化
Python数据类型转换 有时候,我们需要对数据内置的类型进行转换,数据类型的转换,你只需要将数据类型作为函数名即可. 以下几个内置的函数可以执行数据类型之间的转换.这些函数返回一个新的对象,表示转换 ...
- iPad之Linux平台实践
updata.... 本文出自 "李晨光原创技术博客" 博客,谢绝转载!
- $.post()提交了数据,return不给跳转
本来Controller接到普通请求,return “somePage”,这样就跳转了.前台用$.post()提交了数据(不需要回调),我了个大草,return那里就不给跳转了这样怎么解决? ajax ...
- 关于Webpack详述系列文章 (第一篇)
WebPack官网地址(https://webpack-china.org/) 1. 什么是WebPack WebPack可以看做是模块打包机:它做的事情是,分析你的项目结构,找到JavaScript ...
- Stack switching mechanism in a computer system
A method and mechanism for performing an unconditional stack switch in a processor. A processor incl ...
- 洛谷——P1816 忠诚
https://www.luogu.org/problem/show?pid=1816#sub 题目描述 老管家是一个聪明能干的人.他为财主工作了整整10年,财主为了让自已账目更加清楚.要求管家每天记 ...
- nuxt.js配置BASE_URL(基本域名)和NODE_ENV(环境变量)
一直以来,开发环境和生产环境的数据接口域名不一样总是困扰着我 每次打测试包或者线上包,我都得手动切换域名,我相信很多人的做法跟这差不多,类似下面这样: (你已经注意到,这个文件已经被我无情的删除了,因 ...
- Altium Designer如何调整鼠标形状
在 里面有一个