Mushroom Gnomes - 2

感觉没啥东西, 用线段树算算每个被覆盖的概率, 坑点是有很多个在同一个点。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 4e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); int A[N], h[N], b[N], X[N], n, m, tot;
double pl[N], pr[N], z[N], val[N]; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
double a[N << ], lazy[N << ];
void push(int rt) {
if(fabs(lazy[rt] - ) > eps) {
a[rt << ] *= lazy[rt];
a[rt << | ] *= lazy[rt];
lazy[rt << ] *= lazy[rt];
lazy[rt << | ] *= lazy[rt];
lazy[rt] = ;
}
}
void build(int l, int r, int rt) {
lazy[rt] = ;
if(l == r) {
a[rt] = ;
return;
}
int mid = l + r >> ;
build(lson); build(rson);
}
void update(int L, int R, double val, int l, int r, int rt) {
if(L > R) return;
if(l >= L && r <= R) {
a[rt] *= val;
lazy[rt] *= val;
return;
}
int mid = l + r >> ;
push(rt);
if(L <= mid) update(L, R, val, lson);
if(R > mid) update(L, R, val, rson);
}
double query(int p, int l, int r, int rt) {
if(l == r) return a[rt];
int mid = l + r >> ;
push(rt);
if(p <= mid) return query(p, lson);
else return query(p, rson);
} int getId(int x) {
return lower_bound(X, X + tot, x) - X + ;
} int main() {
scanf("%d%d", &n, &m);
for(int i = ; i <= n; i++) {
scanf("%d%d", &A[i], &h[i]);
scanf("%lf%lf", &pl[i], &pr[i]);
pl[i] /= ; pr[i] /= ;
X[tot++] = A[i];
X[tot++] = A[i] + h[i];
X[tot++] = A[i] - h[i];
}
for(int i = ; i <= m; i++) {
scanf("%d%lf", &b[i], &z[i]);
X[tot++] = b[i];
}
sort(X, X + tot);
tot = unique(X, X + tot) - X;
build(, tot, );
for(int i = ; i <= m; i++) {
val[getId(b[i])] += z[i];
}
for(int i = ; i <= tot; i++) {
update(i, i, val[i], , tot, );
}
for(int i = ; i <= n; i++) {
update(getId(A[i]) + , getId(A[i] + h[i]), - pr[i], , tot, );
update(getId(A[i] - h[i]), getId(A[i]) - , - pl[i], , tot, );
}
double ans = ;
for(int i = ; i <= tot; i++) {
ans += query(i, , tot, );
}
printf("%.12f\n", ans);
return ;
} /*
*/

Codeforces 138C Mushroom Gnomes - 2 线段树的更多相关文章

  1. codeforces Good bye 2016 E 线段树维护dp区间合并

    codeforces Good bye 2016 E 线段树维护dp区间合并 题目大意:给你一个字符串,范围为‘0’~'9',定义一个ugly的串,即串中的子串不能有2016,但是一定要有2017,问 ...

  2. codeforces 22E XOR on Segment 线段树

    题目链接: http://codeforces.com/problemset/problem/242/E E. XOR on Segment time limit per test 4 seconds ...

  3. Codeforces 588E. A Simple Task (线段树+计数排序思想)

    题目链接:http://codeforces.com/contest/558/problem/E 题意:有一串字符串,有两个操作:1操作是将l到r的字符串升序排序,0操作是降序排序. 题解:建立26棵 ...

  4. Codeforces Gym 100803G Flipping Parentheses 线段树+二分

    Flipping Parentheses 题目连接: http://codeforces.com/gym/100803/attachments Description A string consist ...

  5. Codeforces GYM 100114 D. Selection 线段树维护DP

    D. Selection Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descriptio ...

  6. Codeforces 444C DZY Loves Colors(线段树)

    题目大意:Codeforces 444C DZY Loves Colors 题目大意:两种操作,1是改动区间上l到r上面德值为x,2是询问l到r区间总的改动值. 解题思路:线段树模板题. #inclu ...

  7. Codeforces 85D Sum of Medians(线段树)

    题目链接:Codeforces 85D - Sum of Medians 题目大意:N个操作,add x:向集合中加入x:del x:删除集合中的x:sum:将集合排序后,将集合中全部下标i % 5 ...

  8. [Codeforces]817F. MEX Queries 离散化+线段树维护

    [Codeforces]817F. MEX Queries You are given a set of integer numbers, initially it is empty. You sho ...

  9. CodeForces 516C Drazil and Park 线段树

    原文链接http://www.cnblogs.com/zhouzhendong/p/8990745.html 题目传送门 - CodeForces 516C 题意 在一个环上,有$n$棵树. 给出每一 ...

随机推荐

  1. C# Winform继承窗体打开设计器白屏的一例解决方法

    环境VS2017 15.5.4,Win10开发过程中,发现一些窗体打开设计器会卡死白屏,另外有一些不会,(两者运行时正常),最小化vs后甚至能把工具箱连带搞黑,严重影响开发效率,经过一天多的对比研究, ...

  2. Linux - 包不同安装方式

    rpm 软件包管理器 安装编译包好的二进制包 方式 rpm -ivh lynx # rpm安装 rpm -e lynx # 卸载包 rpm -e lynx --nodeps # 强制卸载 rpm -q ...

  3. JavaScript之Dom1|DOM2|DOM3之DOM1【节点层次】

    长文慎读. 导航: 1.节点层次 2.Node类型 3.Document类型 4.Element类型 5.Text类型 6.Comment类型 7.CDATASection类型 8.DocumentT ...

  4. vue学习起步:了解下

    渐进式 有这么一句话,vue是渐进式框架. 抽取“渐进式框架”和“自底向上增量开发的设计”这两个概念是什么?中的解释: 渐进式代表的含义是:主张(主张指使用时的硬性要求)最少.来个对比就知道什么叫主张 ...

  5. Faster rcnn代码理解(3)

    紧接着之前的博客,我们继续来看faster rcnn中的AnchorTargetLayer层: 该层定义在lib>rpn>中,见该层定义: 首先说一下这一层的目的是输出在特征图上所有点的a ...

  6. 使用 Linux 系统调用的内核命令【转】

    转自:http://www.ibm.com/developerworks/cn/linux/l-system-calls/ 探究 SCI 并添加自己的调用 Linux® 系统调用 —— 我们每天都在使 ...

  7. phantomjs 截取twitter的网页(动态生成的页面)

    // This example shows how to render pages that perform AJAX calls// upon page load.//// Instead of w ...

  8. 001_ansible通过堡垒机登录

    一. 之前一直通过跳板机登录线上服务器,ssh可以的,如下图所示 vim ~/.ssh/config ssh xx.xx.xx.xx线上服务器是可以的,但是ansible执行显示目标主机不可达,其实a ...

  9. 非root用户执行java进程报错:fork: retry:资源暂时不可用

    vim /etc/security/limits.conf # End of file *           soft   nproc        65535 *           hard   ...

  10. zabbix系列(八)zabbix添加对web页面url的状态监控

    通过zabbi做web监控不仅仅可以监控到站点的响应时间,还可以根据站点返回的状态码,或者响应时间做报警 1.对需要监控的主机添加web监控   在configuration—hosts 中打开主机列 ...