Codeforces 138C 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 线段树的更多相关文章
- codeforces Good bye 2016 E 线段树维护dp区间合并
codeforces Good bye 2016 E 线段树维护dp区间合并 题目大意:给你一个字符串,范围为‘0’~'9',定义一个ugly的串,即串中的子串不能有2016,但是一定要有2017,问 ...
- codeforces 22E XOR on Segment 线段树
题目链接: http://codeforces.com/problemset/problem/242/E E. XOR on Segment time limit per test 4 seconds ...
- Codeforces 588E. A Simple Task (线段树+计数排序思想)
题目链接:http://codeforces.com/contest/558/problem/E 题意:有一串字符串,有两个操作:1操作是将l到r的字符串升序排序,0操作是降序排序. 题解:建立26棵 ...
- Codeforces Gym 100803G Flipping Parentheses 线段树+二分
Flipping Parentheses 题目连接: http://codeforces.com/gym/100803/attachments Description A string consist ...
- Codeforces GYM 100114 D. Selection 线段树维护DP
D. Selection Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descriptio ...
- Codeforces 444C DZY Loves Colors(线段树)
题目大意:Codeforces 444C DZY Loves Colors 题目大意:两种操作,1是改动区间上l到r上面德值为x,2是询问l到r区间总的改动值. 解题思路:线段树模板题. #inclu ...
- Codeforces 85D Sum of Medians(线段树)
题目链接:Codeforces 85D - Sum of Medians 题目大意:N个操作,add x:向集合中加入x:del x:删除集合中的x:sum:将集合排序后,将集合中全部下标i % 5 ...
- [Codeforces]817F. MEX Queries 离散化+线段树维护
[Codeforces]817F. MEX Queries You are given a set of integer numbers, initially it is empty. You sho ...
- CodeForces 516C Drazil and Park 线段树
原文链接http://www.cnblogs.com/zhouzhendong/p/8990745.html 题目传送门 - CodeForces 516C 题意 在一个环上,有$n$棵树. 给出每一 ...
随机推荐
- Service的线程、工作线程、权限及系统Service
Service组件和其他组件一样,都是运行于应用的主线程当中,它们都运行于同一个单一的线程中. 可以把Service简单的理解成一个没有界面显示的Activity(这个比喻其实并不准确,因为Servi ...
- shiro自定义realm认证(五)
上一节介绍了realm的作用: realm:需要根据token中的身份信息去查询数据库(入门程序使用ini配置文件),如果查到用户返回认证信息,如果查询不到返回null.token就相当于是对用户输入 ...
- 一文看懂汽车电子ECU bootloader工作原理及开发要点
随着半导体技术的不断进步(按照摩尔定律),MCU内部集成的逻辑功能外设越来越多,存储器也越来越大.消费者对于汽车节能(经济和法规对排放的要求)型.舒适性.互联性.安全性(功能安全和信息安全)的要求越来 ...
- ES系列一、CentOS7安装ES 6.3.1、集成IK分词器
Elasticsearch 6.3.1 地址: wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3. ...
- rsync同步(winxdows到linux/linux到linxu同步)
1.什么是rsync? -rsync是类unix系统下的数据镜像备份工具——remote sync.一款快速增量备份工具 Remote Sync,远程同步 支持本地复制,或者与其他SSH.rsync主 ...
- Android: SlidingDrawer(滑动式抽屉)
Android控件之SlidingDrawer(滑动式抽屉)详解与实例 一.简介 SlidingDrawer隐藏屏外的内容,并允许用户通过handle以显示隐藏内容.它可以垂直或水平滑动,它有俩个V ...
- HTML常用特殊字符
网页特殊符号HTML代码大全 HTML特殊字符编码大全:往网页中输入特殊字符,需在html代码中加入以&开头的字母组合或以&#开头的数字.下面就是以字母或数字表示的特殊符号大全. ...
- GitHub学习一-本地电脑与GitHub绑定
1.创建ssh key $ ssh-keygen -t rsa -C "your_email@youremail.com"安装完git,右键git bash here,创建ssh ...
- PYTHON-面向对象-练习-王者荣耀 对砍游戏
# 王者荣耀 对砍游戏# 两个英雄可以对砍 如果血量小于等于0 就GG# 所需的对象# 英雄对象""" 亚瑟 属性 类型 血量 名称 技能 Q 跳起来给你一刀 伤害50 ...
- Android TimeAnimator
TimeAnimator:提供了一个简单的回调机制,通过 TimeAnimator.TimeListener,在动画的每一帧处通知你.这个动画器没有时间,插值或是对象值设定.回调监听器为每一帧动画接受 ...