CDOJ 383 Japan Tree-like array

Source: Internet
Author: User

Japan

Time Limit:1 Sec

Memory limit:256 MB

Topic Connection http://acm.uestc.edu.cn/#/problem/show/383
Description

Japan plans to welcome the ACM ICPC World Finals and a lot of roads must is built for the venue. Japan is Tall Island withNCities on the East coast andMCities on the West coast (1≤M≤10000 ,1≤N≤10000 ).KSuperhighways would be build. (1≤K≤1000000 ) Cities on each coast is numbered 1,2, Each superhighway are straight line and connects city in the East coast with city of the West coast. The funding for the construction are guaranteed by ACM. A major portion of the sum is determined by the number of crossings between superhighways. At the most of the superhighways cross at the one location. Write a program that calculates the number of the crossings between superhighways.

Input

The input file starts withT-The number of test cases. Each test case starts with three numbers–N, M, K. Each of the next K lines contains, numbers–the numbers of cities connected by the superhighway. The first one is the number of the city on the East coast and second one are the number of the city of the West COAST.

Output

For each test case, write one line in the Output:test Case number: (Number of crossings)

Sample Input

1
3 4 4
1 4
2 3
3 2
3 1

Sample Output

Test Case 1:5
HINT

Test instructions

There are n cities on the left, m cities on the right, and then K lines, asking you how many intersections there are.

Exercises

This problem is generally related to the number of reverse order, so the reverse number

After sorting, ensure that the sequence

Code:

//Qscqesze#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<bitset>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>#include<stack>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineMAXN 200500#defineMoD 1001#defineEPS 1e-9#definePi 3.1415926intNum;//const int INF=0X7FFFFFFF;Constll inf=999999999; inline ll read () {ll x=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}//*************************************************************************************intD[MAXN];intN =10050;structnode{intx, y;};BOOLCMP (node A,node b) {if(a.x==b.x)returnA.y>b.y; returnA.x>b.x;} Node A[MAXN];intLowbit (intx) {returnx& (-x);}voidUpdata (intx) {     while(x<=N) {d[x]+=1; X+=lowbit (x); }}intSumintx) {    intAns =0;  while(x) {ans+=D[x]; X-=lowbit (x); }    returnans;}intn,m,k;intMain () {intt=read ();  for(intcas=1; cas<=t;cas++) {memset (A,0,sizeof(a)); memset (d,0,sizeof(d)); scanf ("%d%d%d",&n,&m,&k);  for(intI=1; i<=k;i++) a[i].x=read (), a[i].y=read (); Sort (a+1, a+k+1, CMP); intAns =0;  for(intI=1; i<=k;i++) {ans+=sum (a[i].y-1);        Updata (A[I].Y); } printf ("Test Case%d:%d\n", Cas,ans); }}

CDOJ 383 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.