题目链接
http://poj.org/problem?id=2482
分析
题面很感人,撩妹子的小trick;
依旧是扫描线法,在此之前需要一步转化,
考虑对于每颗星星,能将其覆盖的矩形右上角的轨迹所组成的矩形,
显然答案变为求一块区域,使得矩形在其上覆盖产生的权值和最大,
建一棵线段树支持区间加和区间查询最大值,从左往右扫描即可,
注意边缘的星星不算,注意对线段的排序方式,和面积并周长并有区别。
AC代码
#include <cstdio>
#include <algorithm>
using namespace std;
inline int read() {
int num = 0;
char c = getchar();
while (c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9')
num = num * 10 + c - '0', c = getchar();
return num;
}
const int maxn = 1e4 + 5;
struct Line {
long long x, y1, y2, k;
bool operator < (const Line& rhs) const {
if (x == rhs.x) return k < rhs.k;
return x < rhs.x;
}
} line[2 * maxn];
struct SegmentTree {
int l, r, ma