voidMake_edge(){ sort(u + 1, u + n + 1, xsort); // x 相同 处理竖边 for(int i = 1; i < n; i++) { if(u[i + 1].x != u[i].x || u[i + 1].y - u[i].y < 2) continue; e[++m].up = u[i].y + 1; e[m].down = u[i + 1].y - 1; e[m].right = u[i].x; } sort(u + 1, u + n + 1, ysort); // y 相同 处理横边 for(int i = 1; i < n; i++) { if(u[i + 1].y != u[i].y || u[i + 1].x - u[i].x < 2) continue; e[++m].up = u[i].y; e[m].left = u[i].x + 1; e[m].right = u[i + 1].x - 1; } sort(e + 1, e + m + 1, esort); }
intlowbit(int x){return x & -x;} voidupdate(int x, int k){while(x <= maxx) {t[x] = t[x] + k; x = x + lowbit(x);}} intquery(int x){int ans = 0; while(x) {ans = ans + t[x]; x = x - lowbit(x);} return ans;}
voidScanning(){ for(int i = 1; i <= m; i++) { int deep = e[i].up; while(!que.empty() && que.top().y <= deep) {update(que.top().x, -1); que.pop();} if(!e[i].left) {update(e[i].right, 1); que.push((edge_end){e[i].right, e[i].down + 1});} else {ans = ans + query(e[i].right) - query(e[i].left - 1);} } }