题目链接
http://acm.hdu.edu.cn/showproblem.php?pid=1828
分析
扫描线法,线段树节点同时记录区间端点是否被覆盖,区间中有几条水平线,
累加答案时,注意线段会有覆盖,因此应加上变化量;
根据记录的水平线数量统计上水平线长度。
AC代码
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
inline int read() {
int num = 0, flag = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') flag = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
num = num * 10 + c - '0', c = getchar();
return flag * num;
}
const int maxn = 5e3 + 5;
struct Line {
int x, y1, y2, k;
bool operator < (const Line& rhs) const {
return x < rhs.x;
}
} line[2 * maxn];
int n, a[2 * maxn];
struct SegmentTree {
int l, r, cnt, len, lf, rf, num;