/*在求周長之前最好線看一下求面積,這樣再求周長回好理解很多。
題目是poj 1177
poj 1151也是這類問題,不過是求面積的,更簡單一些。
*/#include
#include
#include
#include
#include
#include
#include
#include
#include
#define cl(arr, val) memset(arr, val, sizeof(arr))
#define rep(i, n) for((i) = 0; (i) < (n); ++(i))
#define for(i, l, h) for((i) = (l); (i) <= (h); ++(i))
#define ford(i, h, l) for((i) = (h); (i) >= (l); --(i))
#define l(x) (x) << 1
#define r(x) (x) << 1 | 1
#define mid(l, r) (l + r) >> 1
#define min(x, y) x < y ? x : y
#define max(x, y) x < y ? y : x
#define e(x) (1 << (x))typedef
long
long
ll;using
namespace
std;
const
int n = 10010
;struct
xline
}line[n];
struct
xnode
}node[n
<<2
];int
ind[n];
intn, m;
void build(int t, int l, int r)
}void up_sum(int t)
void up_lsum(int t)
else
if(node[t].r - node[t].l > 1
) else
}void updata(int t, int l, int r, bool c)
int mid =mid(node[t].l, node[t].r);
if(r <=mid) updata(l(t), l, r, c);
else
if(l >=mid) updata(r(t), l, r, c);
else
up_sum(t);
up_lsum(t);
}inline
int iabs(int
x) int find(int x)
return0;
}int
main()
sort(ind, ind + n*2
); sort(line, line + n*2
); m = 1
;
for(i = 0; i < n*2 - 1; ++i)
/*for(i = 0; i < m; ++i)
printf("%d ", ind[i]);
cout << endl;
*/build(
1, 0, m-1); //
建樹int ans = 0
;
int presum = 0
;
for(i = 0; i < 2*n - 1; ++i)
updata(
1, find(line[2*n-1].y1), find(line[2*n-1].y2), 0); //
別忘了最後乙個出邊要刪除
ans += iabs(node[1].sum -presum);
printf(
"%d\n
", ans);
}return0;
}
我的線段樹掃瞄線問題模板
在求周長之前最好線看一下求面積,這樣再求周長回好理解很多。題目是poj 1177 poj 1151也是這類問題,不過是求面積的,更簡單一些。include include include include include include include include include define c...
線段樹掃瞄線模板
hdu 1542 hdu 1255 hdu 3642平面面積並 題目鏈結 超級棒的題解 include using namespace std const int n 210 int cnt n 2 double sum n 2 x n struct seg seg double a,double ...
線段樹 掃瞄線區間模板
線段樹 掃瞄線基礎模板 掃瞄線與普通的線段樹區別要認清,這裡線是連續的,其他的型別單點是離散的 include include include using namespace std int n const int maxn 10000 struct node void get int a,int ...