POJ3067 Japan tree-like array

Source: Internet
Author: User
Tags cas

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

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.