"BZOJ1818" [Cqoi2010] Inner white point description infinite square grid with n black vertices, all other vertices are white (the vertices of the mesh are the points of the integer coordinates, also known as the whole hour). Every second, all internal white dots darken at the same time, until there is no inner white spot. Your task is to count the number of black dots in the last grid. Definition of inner white point: a white dot P (x, y) is the inner white point when and only if P has at least one black point on the left and right side of the horizontal line (that is, the presence of X1 < x < X2 makes (x1,y) and (x2,y) both black dots), And there is at least one black point at the top and bottom of the vertical line (that is, the presence of Y1 < Y < Y2 makes (x,y1) and (x,y2) both black dots). Input inputs The first line contains an integer n, which is the number of initial black dots. The following n rows each row contains two integers (x, y), which is the coordinates of a black point. No two black dots have the same coordinates, and the absolute value of the coordinates does not exceed 109. Output outputs only one row, containing the final number of black dots. If the discoloration process never terminates, output-1. Sample Input4
2 p
2 0
-2 0
0-2Sample Output5
Data range
36% of data satisfies: N < = 500
64% of data satisfies: n < = 30000
100% of data satisfies: n < = 100000
puzzle: Easy to find, for the same x coordinate points, the most useful point must be the Y coordinate the smallest and largest point; Y the same, the most useful is the X coordinate the smallest and largest point. and the new addition of the internal white point x and Y coordinates must not be better than the original, so ... The discoloration process lasts for up to 1 seconds.
So we discretized, to find the x-coordinate of the same y when the minimum and maximum value and Y is the same as the minimum maximum value of x, and then can be seen as a bunch of segments to find the number of intersections of these segments. Use scan line + Tree array.
#include <cstdio> #include <cstring> #include <iostream> #include <vector> #include < algorithm>using namespace Std;const int maxn=100010;typedef long long ll;int n,mx,my;ll ans;int xl[maxn],xr[maxn],yl[ Maxn],yr[maxn],s[maxn];struct point{int x, y;} P[maxn];struct node{int val,org;} Num[maxn];vector<int> q1[maxn],q2[maxn];vector<int>::iterator it;bool CMPV (const node &a,const node &B) {return a.val<b.val;} BOOL Cmpx (const point &a,const point &b) {return a.x<b.x;} inline void updata (int x,int val) {for (int i=x;i<=mx;i+=i&-i) S[i]+=val;} inline int query (int x) {int i,ret=0;for (i=x;i;i-=i&-i) ret+=s[i];return ret;} inline Int rd () {int Ret=0,f=1;char gc=getchar (); while (gc< ' 0 ' | | Gc> ' 9 ') {if (gc== '-') F=-f;gc=getchar ();} while (gc>= ' 0 ' &&gc<= ' 9 ') ret=ret*10+ (gc^ ' 0 '), Gc=getchar (); return ret*f;} int main () {n=rd (); int i;for (i=1;i<=n;i++) num[i].val=rd (), P[i].y=rd (), Num[i].org=i;sort (NUM+1,NUM+N+1,CMPV); for (i=1;i<=n;i++) {if (i==1| | Num[i].val>num[i-1].val) mx++;p [Num[i].org].x=mx;} for (i=1;i<=n;i++) Num[i].val=p[i].y,num[i].org=i;sort (NUM+1,NUM+N+1,CMPV), for (i=1;i<=n;i++) {if (i==1| | Num[i].val>num[i-1].val) my++;p [Num[i].org].y=my;} memset (Xl,0x3f,sizeof (XL)), memset (yl,0x3f,sizeof (YL)), for (i=1;i<=n;i++) {Xr[p[i].x]=max (XR[P[I].X],P[I].Y), Xl[p[i].x]=min (XL[P[I].X],P[I].Y); Yr[p[i].y]=max (yr[p[i].y],p[i].x), Yl[p[i].y]=min (yl[p[i].y],p[i].x);} for (i=1;i<=mx;i++) q1[xl[i]].push_back (i), q2[xr[i]].push_back (i), and for (i=1;i<=my;i++) {for (It=q1[i].begin (); It!=q1[i].end (); it++) Updata (*it,1); Ans+=query (Yr[i])-query (yl[i]-1); for (It=q2[i].begin (); It!=q2[i].end (); it++) Updata (*it,-1);} printf ("%lld", ans); return 0;}
BZOJ1818 [Cqoi2010] Internal White-point scan line + tree-like array