POJ 3067 Japan (tree array/reverse order number)

Source: Internet
Author: User

Japan
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 22258 Accepted: 5995

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 with N cities on the East coast and M cities on the West coast (M <=, N <= 1000). K superhighways would be build. 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 with t-the number of test cases. Each test case is 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 standard output:
Test Case Number: (Number of crossings)

Sample Input

13 4 41 42 33 23 1

Sample Output

Test Case 1:5

Source

Southeastern Europe 2006


#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include <    Stdlib.h>using namespace Std;int n,m,k;__int64 c[1000100];struct node{int x; int y;}    Q[1000500];bool CMP (node A,node b) {if (a.x==b.x) {return a.y<=b.y;    } else {return a.x<b.x; }}int lowbit (int x) {return x& (-X);}        void Updata (int i,int t) {while (i<=m) {C[i] + = t;    i = i + lowbit (i);    }}__int64 getsum (int i) {__int64 sum = 0;        while (i>0) {sum + = C[i];    i = I-lowbit (i); } return sum;}    int main () {int T;    int p = 0;    scanf ("%d", &t);        while (t--) {scanf ("%d%d%d", &n,&m,&k);        Memset (C,0,sizeof (c));        for (int i=0; i<k; i++) {scanf ("%d%d", &q[i].x,&q[i].y);        } __int64 ans = 0;        Sort (q,q+k,cmp);            for (int i=0; i<k; i++) {updata (q[i].y,1); Ans + = GetSUM (m)-getsum (Q[I].Y);    } printf ("Test Case%d:%i64d\n", ++p,ans); } return 0;}


POJ 3067 Japan (tree array/reverse order number)

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.