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