警示后人

P5816 [CQOI2010] 内部白点

如果你也像我这么写(这个代码是不能 AC 的): ```cpp #include <bits/stdc++.h> const signed bufsize=5e6;__inline__ __attribute((always_inline))char Getchar(){static char buf[bufsize],*p1=buf,*p2=buf;return(p1==p2&&(p2=(p1=buf)+fread(buf,1,bufsize,stdin),p1==p2)?-1:*p1++);}template<class T>__inline__ __attribute((always_inline))void fr(register T&x){register char c,f;x^=x,c^=c,f^=f;do c^45?0:f|=1;while(c=Getchar(),c<48||c>57);do x=(x<<1)+(x<<3)+(c^48);while(c=Getchar(),c>47&&c<58);f?--x^=-1:0;} using namespace std; namespace lgh {void main();} signed main() { // freopen("2.in", "r", stdin); // freopen("2.out", "w", stdout); return lgh::main(), 0;} namespace lgh { const int Maxn = 1e5 + 5, INF = 0x3f3f3f3f; int N; struct Point {int x, y;} pt[Maxn]; int X[Maxn], Xtop; int Y[Maxn], Ytop; int hd[Maxn], tl[Maxn], top[Maxn]; struct Bit { int sum[Maxn]; #define lowbit(x) ((x) & -(x)) void modify(int x, int k) { while (x <= Xtop) { sum[x] += k; x += lowbit(x); } } int query(int x) { int res = 0; while (x >= 1) { res += sum[x]; x -= lowbit(x); } return res; } } bit; void main() { fr(N); for (int i = 1; i <= N; ++i) { fr(pt[i].x), fr(pt[i].y); X[++Xtop] = pt[i].x, Y[++Ytop] = pt[i].y; } sort(pt + 1, pt + N + 1, [](const Point &a, const Point &b) {return a.y < b.y;}); sort(X + 1, X + Xtop + 1); Xtop = unique(X + 1, X + Xtop + 1) - (X + 1); sort(Y + 1, Y + Ytop + 1); Ytop = unique(Y + 1, Y + Ytop + 1) - (Y + 1); fill(hd, hd + N + 1, INF); for (int i = 1; i <= N; ++i) { pt[i].x = lower_bound(X + 1, X + Xtop + 1, pt[i].x) - X; pt[i].y = lower_bound(Y + 1, Y + Ytop + 1, pt[i].y) - Y; hd[pt[i].y] = min(hd[pt[i].y], pt[i].x); tl[pt[i].y] = max(tl[pt[i].y], pt[i].x); top[pt[i].x] = max(top[pt[i].x], pt[i].y); } int ans = 0; for (int i = 1, now = 1; i <= Ytop; ++i) { if (tl[i] - hd[i] < 2) continue; for (; now <= N && pt[now].y < i; ++now) { if (pt[now].y != top[pt[now].x]) { if (bit.query(pt[now].x) - bit.query(pt[now].x - 1) == 0) bit.modify(pt[now].x, 1); } else { if (bit.query(pt[now].x) - bit.query(pt[now].x - 1) == 1) bit.modify(pt[now].x, -1); } } ans += bit.query(tl[i] - 1) - bit.query(hd[i]); } printf("%d", N + ans); } } ```
by liugh_ @ 2024-04-27 13:44:53


|