Bzoj 1818 Internal White point (discretized + tree Array)

Source: Internet
Author: User

This is the weakening version of 1227.

Draw a picture or just a little proof to know that there will be no more than one change.

So we just need to count how many white dots will darken, in other words, how many white spots have black dots up or down.

The discretization of the horizontal axis, because there is no black spot in the column is meaningless, the answer also did not contribute.

Then process each row, for each row, maintain a bit that is what points will contribute, the bit will only have n times to modify, n query.

So the complexity of Time is O (Nlogn).

# include <cstdio># include<cstring># include<cstdlib># include<iostream># include<vector># include<queue># include<stack># include<map># include<Set># include<cmath># include<algorithm>using namespacestd;# define Lowbit (x) ( x)& (-x)) # define PI3.1415926535# define EPS 1e-9# define MOD9999973# define INF1000000000# define MEM (A, B) memset (A, B,sizeof(a) # define for (I,a,n) for(intI=a; i<=n; ++i) # define FO (I,a,n) for(intI=a; i<n; ++i) # define bug puts ("H"); # define LCH P<<1, l,mid# define RCH p<<1|1, mid+1, r# define MP make_pair# define PB push_backtypedef pair<int,int>pii;typedef Vector<int>vi;# pragma comment (linker,"/stack:1024000000,1024000000") typedefLong LongLL;intScan () {intres=0, flag=0; Charch; if((Ch=getchar ()) = ='-') flag=1; Else if(ch>='0'&&ch<='9') res=ch-'0';  while((Ch=getchar ()) >='0'&&ch<='9') res=res*Ten+ (ch-'0'); returnflag?-res:res;}voidOut (inta) {if(a<0) {Putchar ('-'); a=-A;} if(a>=Ten) Out (A/Ten); Putchar (A%Ten+'0');}Const intn=100005;//Code begin ...structnode{intx, y;} Node[n];vi V, vv;intCol[n], vis[n], tree[n], N;BOOLComp (Node A, Node B) {if(A.Y==B.Y)returna.x<b.x; returnA.y>b.y;}voidAddintXintVal) { while(x<=n) Tree[x]+=val, x+=lowbit (x);}intQueryintx) {    intres=0;  while(x) res+=tree[x], x-=lowbit (x); returnRes;}intMain () {LL ans=0; scanf ("%d",&N); For (I,1, N) scanf ("%d%d",&node[i].x,&node[i].y), V.PB (node[i].x);    Sort (V.begin (), V.end ()); intSiz=unique (V.begin (), V.end ())-V.begin (); Sort (Node+1, node+n+1, comp); For (I,1, N) {node[i].x=lower_bound (V.begin (), V.begin () +siz,node[i].x)-v.begin () +1; ++col[node[i].x]; }    intnow=1;  while(now<=N) {vv.clear (); VV.PB (node[now].x); ++Now ;  while(now<=n&&node[now].y==node[now-1].Y) VV.PB (node[now].x), + +Now ; Siz=vv.size (); FO (i,1, siz) ans+= (query (vv[i]-1)-query (vv[i-1])); FO (i,0, Siz) {            ++Vis[vv[i]]; if(vis[vv[i]]==1&&col[vv[i]]>1) Add (Vv[i],1); Else if(vis[vv[i]]==col[vv[i]]&&col[vv[i]]>1) Add (vv[i],-1); }} printf ("%lld\n", ans+N); return 0;}
View Code

Bzoj 1818 Internal White point (discretized + tree Array)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.