萌新求助 #7 一直 WA

P1502 窗口的星星

``` #include<bits/stdc++.h> const int maxn = 10005, maxt = 15; int n, t, w, h; struct scanline { db h, l, r, f; bool friend operator < (scanline a, scanline b) { if(a.h == b.h) return a.f > b.f; return a.h < b.h; } }line[maxn << 1]; db X[maxn << 1]; int tot; struct seg { int sum[maxn << 4], t[maxn << 4]; int lc(int x) {return x << 1;} int rc(int x) {return x << 1 | 1;} void clear() { memset(sum, 0, sizeof sum); memset(t, 0, sizeof t); } void build(int x, int l, int r) { sum[x] = t[x] = 0; if(l == r) return; int mid = (l + r) >> 1; build(lc(x), l, mid); build(rc(x), mid + 1, r); } void upd(int x) {sum[x] = max(sum[lc(x)], sum[rc(x)]);} void push_down(int x) { t[lc(x)] += t[x]; t[rc(x)] += t[x]; sum[lc(x)] += t[x]; sum[rc(x)] += t[x]; t[x] = 0; } void modify(int x, int l, int r, int L, int R, int k) { if(L <= X[l] && X[r] <= R) { sum[x] += k; t[x] += k; return; } int mid = (l + r) >> 1; push_down(x); if(L <= X[mid]) modify(lc(x), l, mid, L, R, k); if(R > X[mid + 1]) modify(rc(x), mid + 1, r, L, R, k); upd(x); } // void query(int x, int l, int r, int L, int R) }T; signed main() { read(t); while(t --) { read(n); read(w); read(h); rep(i, 1, n) { db x, y, l; read(x); read(y); read(l); line[i] = {y, x, x + w - 0.4, l}; line[i + n] = {y + h - 0.4, x, x + w - 0.4, -l}; X[i] = x; X[i + n] = x + w - 0.4; } n <<= 1; std :: sort(line + 1, line + n + 1); std :: sort(X + 1, X + n + 1); tot = std :: unique(X + 1, X + n + 1) - X - 1; T.build(1, 1, tot); int ans = 0; rep(i, 1, n - 1) { T.modify(1, 1, tot, line[i].l, line[i].r, line[i].f); MAX(ans, T.sum[1]); } print(ans); T.clear(); } return 0; } /* */ ``` rep 是宏定义的 for
by 8atemak1r @ 2022-09-20 02:36:02


将 R > X[mid + 1] 改为 R >= X[mid + 1]
by _CY_ @ 2022-09-20 09:22:44


|