题目链接
http://acm.hdu.edu.cn/showproblem.php?pid=1255
分析
与普通的面积并不同的是,
我们要维护被覆盖了至少两次的区间,还需同时维护至少覆盖了一次的区间,
后者是很容易维护的,而对于前者来说,
若整个区间被至少覆盖了两次,则结果为区间长度,
否则,若区间长度为 1 1 1,则结果为 0 0 0,
否则,若区间被覆盖了一次,则结果为子区间被至少覆盖一次的长度之和,
否则结果为子区间被至少覆盖两次的长度之和。
AC代码
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 1e3 + 5;
struct Line {
int k;
double x, y1, y2;
bool operator < (const Line& rhs) const {
return x < rhs.x;
}
} line[2 * maxn];
double x1, y1, x2, y2, a[2 * maxn];
struct SegmentTree {
int l, r, cnt;
double len1, len2;
} t[8 * maxn];
inline void up(int p) {
if (t[p].cnt) t[p].len1 = a[t[p].r + 1] - a[t[p]