# 题解

y $y$轴为基准建立扫描线，yh$y-h$处加上一条线段， y <script type="math/tex" id="MathJax-Element-7">y</script>处去掉。

# 代码

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N = 1e5+5;

struct Star {
int x, y, b;
};

struct Seg {
};

struct SegmentTree {
#define lson (rt<<1)
#define rson ((rt<<1)|1)
#define MID ((L+R)>>1)
#define lsonPara lson, L, MID
#define rsonPara rson, MID+1, R

const static int TN = N << 2;

int t[TN];
int lazy[TN];

void pushUp(int rt) {
t[rt] = max(t[lson], t[rson]);
}

void pushDown(int rt, int L, int R) {
if (lazy[rt]) {
lazy[lson] += lazy[rt];
lazy[rson] += lazy[rt];
t[lson] += lazy[rt];
t[rson] += lazy[rt];
lazy[rt] = 0;
}
}

void build(int rt, int L, int R) {
lazy[rt] = t[rt] = 0;
if (L == R) return;
build(lsonPara);
build(rsonPara);
pushUp(rt);
}

void modify(int rt, int L, int R, int l, int r, int v) {
if (l > R || r < L) return;
if (l <= L && r >= R) {
lazy[rt] += v;
t[rt] += v;
} else {
pushDown(rt, L, R);
modify(lsonPara, l, r, v);
modify(rsonPara, l, r, v);
pushUp(rt);
}
}
};

Star star[N];
int x[N], y[N*2], l[N];
vector<Seg> a[N*2];
SegmentTree st;

int main() {
int n, w, h;
while (scanf("%d%d%d", &n, &w, &h) == 3) {
for (int i = 0; i < n; i++) {
scanf("%d%d%d", &star[i].x, &star[i].y, &star[i].b);
x[i] = star[i].x;
y[i] = star[i].y - h, y[n+i] = star[i].y;
}
sort(x, x + n);
sort(y, y + 2 * n);
int xn = unique(x, x + n) - x;
int yn = unique(y, y + 2 * n) - y;

int lb = 0;
for (int i = 0; i < xn; i++) {
while (x[i] - x[lb] >= w) lb++;
l[i] = lb;
}

for (int i = 0; i < n; i++) {
int x2 = lower_bound(x, x + xn, star[i].x) - x;
int x1 = l[x2];
int y1 = lower_bound(y, y + yn, star[i].y - h) - y;
int y2 = lower_bound(y, y + yn, star[i].y) - y;
a[y1].push_back(Seg(x1, x2, star[i].b));
a[y2].push_back(Seg(x1, x2, -star[i].b));
}

st.build(1, 0, xn);
int ans = 0;
for (int i = 0; i < yn; i++) {
for (int j = 0; j < a[i].size(); j++) {
Seg &cur = a[i][j];
st.modify(1, 0, xn, cur.x1, cur.x2, cur.add);
}
ans = max(ans, st.t[1]);
a[i].clear();
}
printf("%d\n", ans);
}
return 0;
}

• 点赞
• 评论
• 分享
x

海报分享

扫一扫，分享海报

• 收藏
• 手机看

分享到微信朋友圈

x

扫一扫，手机阅读

• 打赏

打赏

ned_chu

你的鼓励将是我创作的最大动力

C币 余额
2C币 4C币 6C币 10C币 20C币 50C币
• 一键三连

点赞Mark关注该博主, 随时了解TA的最新博文
02-26 1563

05-13 1009
06-17 607
07-13 1002
03-25 130
10-16 857