POJ 3067-japan-tree-like array

Source: Internet
Author: User

Sort the bridge on the left-hand side, the same on the left.

Then insert the tree-like array, Getsum is the bridge before the bridge, which is the intersection of the bridge.

1#include <cstdio>2#include <algorithm>3#include <cstring>4#include <vector>5 6 using namespacestd;7 8 Const intMAXN = 2e3+ -;9 intn,m,k,t;Ten  One structline{ A     intL,r; -Lineint_l=0,int_r=0): L (_l), R (_r) {} -  the     BOOL operator< (ConstLine &b)Const -     { -         if(L = = B.L)returnR <B.R; -         Else returnL <B.L; +     } - }; +  AVector <line>Highway; at intC[MAXN]; -  - intLowbit (intx) - { -     returnx& (-x); - } in  - voidUpdateintx) to { +      while(x <=M) -     { theC[X] + =1; *X + =lowbit (x); $     }Panax Notoginseng } -  the Long LongGetsum (intx) + { A     Long Longsum =0; the      while(x >=1) +     { -Sum + =C[x]; $X-=lowbit (x); $     } -     returnsum; - } the  - intMain ()Wuyi { thescanf"%d",&T); -     intCAS =0; Wu      while(t--) -     { Aboutscanf"%d%d%d",&n,&m,&K); $ highway.clear (); -Memset (c,0,sizeofc); -          for(intI=0, l,r;i<k;i++) -         { Ascanf"%d%d",&l,&R); + Highway.push_back (Line (l,r)); the         } - sort (Highway.begin (), Highway.end ()); $  the         Long Longres =0; the          for(intI=0; I) the         { the Update (HIGHWAY[I].R); -Res + = I-getsum (HIGHWAY[I].R) +1; in         } the  theprintf"Test Case%d:%lld\n",++cas,res); About     } the}

POJ 3067-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.