Codeforces Round#99 E(Div2)

遗世独立的理想乡

题意不赘述了……大体思路就是用线段树成段更新来维护每一个位置的存活概率,然后再用单点查询回来计算期望就行了,裸题。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
const int maxn = 1e5 + 100;
struct segtree{
	double mr[maxn << 4], col[maxn << 4];
	void PushDown(int rt){
		if (col[rt] < 1){
			col[rt << 1] *= col[rt];
			col[rt << 1 | 1] *= col[rt];
			mr[rt << 1] *= col[rt];
			mr[rt << 1 | 1] *= col[rt];
			col[rt] = 1;
		}
	}
	void build(int l, int r, int rt){
		col[rt] = mr[rt] = 1;
		if (l == r) return;
		int m = (l + r) >> 1;
		build(lson); build(rson);
	}
	void update(int ll, int rr, double c, int l, int r, int rt){
		if (ll <= l && rr >= r){
			col[rt] *= c;
			mr[rt] *= c;
			return;
		}
		PushDown(rt);
		int m = (l + r) >> 1;
		if (ll <= m) update(ll, rr, c, lson);
		if (rr > m) update(ll, rr, c, rson);
	}
	double query(int pos, int l, int r, int rt){
		if (l == r) return mr[rt];
		PushDown(rt);
		int m = (l + r) >> 1;
		if (pos <= m) return query(pos, lson);
		else return query(pos, rson);
	}
};
segtree solver;
struct OP{
	int l, r, p;
	double flag;
};
vector<OP> op;
vector<int> Y;
map<int, int> H;
int B[maxn], Z[maxn];
int main(){
	int n, m;
	while(scanf("%d%d", &n, &m) == 2){
		Y.clear(); H.clear(); op.clear();
		int a, h, l, r;
		for (int i = 0; i < n; i++){
			scanf("%d%d%d%d", &a, &h, &l, &r);
			Y.push_back(a - h); Y.push_back(a + h); Y.push_back(a);
			op.push_back((OP){a - h, a, 1, (100 - l) / 100.0});
			op.push_back((OP){a, a + h, 0, (100 - r) / 100.0});
		}
		for (int i = 0; i < m; i++){
			scanf("%d%d", &B[i], &Z[i]);
			Y.push_back(B[i]);
		}
		sort(Y.begin(), Y.end());
		Y.erase(unique(Y.begin(), Y.end()), Y.end());
		int k = Y.size();
		for (int i = 0; i < k; i++)
			H[Y[i]] = i + 1;
		solver.build(0, k, 1);
		for (int i = 0; i < (int)op.size(); i++)
			if (op[i].p) solver.update(H[op[i].l], H[op[i].r] - 1, op[i].flag, 0, k, 1);
			else solver.update(H[op[i].l] + 1, H[op[i].r], op[i].flag, 0, k, 1);
		double ans = 0;
		for (int i = 0; i < m; i++)
			ans += (double)Z[i] * solver.query(H[B[i]], 0, k, 1);
		printf("%.4lf\n", ans);
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值