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