There are n cities on the left of a city, from top to bottom and M cities on the right.
Now to build K high-speed rail, the starting point on the left, the end to the right,
Ask how many intersections you have (only 2 lines pass at any intersection).
Sort + Tree-like array, insert points to ask paragraph.
After sorting, click Start from small to large sweep again,
A[J] Indicates the number of end points in the front I line, which is J.
C[J] A tree-like array of a[j].
Note: The final result is to use a long long
1#include <algorithm>2#include <cstdio>3#include <cstring>4 using namespacestd;5 Const intmaxn= ++5;6 intC[MAXN];7 structEdge8 {9 intu,v;Ten}edge[maxn*MAXN]; One intn,m; A BOOLCMP (Edge I,edge j) - { - if(i.u==j.u) the returni.v<j.v; - returni.u<j.u; - } - intLowbit (intx) + { - returnx& (-x); + } A intSumintx) at { - inttemp=0; - while(x>0){ -temp+=C[x]; -x-=lowbit (x); - } in returntemp; - } to voidUpdateintXintnum) + { - while(x<=m) { thec[x]+=num; *x+=lowbit (x); $ }Panax Notoginseng } - intMain () the { + inttest; A intcas=0; thescanf"%d",&test); + while(test--){ -cas++; $ intK; $scanf"%d%d%d",&n,&m,&k); - for(intI=1; i<=k;i++) -scanf"%d%d",&edge[i].u,&edge[i].v); theSort (edge+1, edge+k+1, CMP); -Memset (c,0,sizeof(c));Wuyi Long Longans=0; the for(intI=1; i<=k;i++){ -Update (EDGE[I].V,1); Wuans+= (Long Long) (I-sum (EDGE[I].V)); - } Aboutprintf"Test Case%d:%i64d\n", Cas,ans); $ } - return 0; -}
View Code
POJ3067 Japan tree-like array