This is Bestcorder Div1 1003 at that time will not do to see the official after the game, and then translated a bit over, and fast, worship the official puzzle.
Attach the official puzzle:
The Soldier of Love
We note that we are asking for the number of segments at least one point across each group.
so we can first ask for the number of segments that are not covered at a point, using nn minus.
We take all of the dots and lines off-line first:
For each line segment, mark the last left end point at his right end.
For each set of points, at a point other than the first point, mark the previous point and record the number of the point.
Then sweep the axis from 1 to 10^6, processing all the marks on each point, first processing the points.
For each point, find his previous point, put the tree-like array in the[P_{now}-1, P_{pre} + 1][P? n ow?? −1,p< Span class= "Vlist" >? pr e?? +1
But what does this tree array record? For each point, find his segment marker, which is the left end of the segment, and add the position of the left endpoint to the tree-like array.
That is, for the current position, the tree array records the sum of the left end points of all the segments on the left side of the right end point. That's itO ((n+m_sum) log10^{6})O((N+m? s?? um) log10< Span class= "Vlist" >? 6??
< Span class= "Mord mathit" > Note: There is one more thing to do, You record 3e5 of the points of the array needs to open twice times, this is very important, I feel good disgusting, because the array is small, and put to hang electricity, return T, let me once to the official question produced suspicion
#include <cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<cstdlib>#include<cmath>#include<cstdlib>#include<vector>#include<queue>using namespaceStd;typedefLong LongLL;Const intinf=0x3f3f3f3f;Const intmaxn=1000000+5;Const intmaxm=300000+5;structpoint{intX,pre,bel; BOOL operator< (ConstPoint &e)Const { returnx<e.x; }} O[MAXM*2];structseg{intL,r; BOOL operator< (ConstSeg &e)Const { returnr<E.R; }} E[MAXM];intC[MAXN];intLowbit (intx) { returnx& (-x);}voidAddinti) { while(i<MAXN) { ++C[i]; I+=lowbit (i); }}intQueryinti) { intsum=0; while(i>0) {sum+=C[i]; I-=lowbit (i); } returnsum;}intANS[MAXM];intMain () {intn,m; while(~SCANF ("%d%d",&n,&m) {memset (c,0,sizeof(c)); memset (ans,0,sizeof(ans)); for(intI=1; i<=n; ++i) scanf ("%d%d",&e[i].l,&E[I].R); intCnt=0; for(intI=1; i<=m; ++i) {intK; scanf ("%d",&k); for(intj=0; j<k; ++j) {scanf ("%d", &o[++cnt].x); O[cnt].bel=i,o[cnt].pre=-1; if(j==0)Continue; O[cnt].pre=o[cnt-1].x; } o[++cnt].x=1e6+1; O[cnt].bel=i,o[cnt].pre=o[cnt-1].x;; } sort (E+1, e+1+N); Sort (o+1, o+1+CNT); intnow=1; for(intI=1; i<=cnt; ++i) { while(now<=n&&e[now].r<o[i].x) {Add (E[NOW].L); now++; } Ans[o[i].bel]+=query (o[i].x-1)-query (o[i].pre);; } for(intI=1; i<=m;++i) printf ("%d\n", N-Ans[i]); } return 0;}
View Code
HDU 5603 The Soldier of Love Offline + Tree array