Japan
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 23111 |
|
Accepted: 6232 |
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 tree-shaped array third question. This problem can be sorted first, x ascending, x same, y ascending and then the inverse logarithm in Y. Probably know how to use a tree-like array for reverse order.
Subscript (starting from 0)-=a[i] smaller than a[i] and the inverse of the previous form.
See code comments for details
1 /*************************************************************************2 > File name:code/poj/3067.cpp3 > Author:111qqz4 > Email: [Email protected]5 > Created time:2015 August 04 Tuesday 10:49 06 Seconds6 ************************************************************************/7 8#include <iostream>9#include <iomanip>Ten#include <cstdio> One#include <algorithm> A#include <cmath> -#include <cstring> -#include <string> the#include <map> -#include <Set> -#include <queue> -#include <vector> +#include <stack> - #defineY0 ABC111QQZ + #defineY1 HUST111QQZ A #defineYn hez111qqz at #defineJ1 CUTE111QQZ - #defineTM CRAZY111QQZ - #defineLR DYING111QQZ - using namespacestd; - #defineREP (i, n) for (int i=0;i<int (n); ++i) -typedefLong LongLL; intypedef unsignedLong LongULL; - Const intINF =0x7fffffff; to Const intn=1e3+5; + - intn,m,k; the intt[n*n/2]; * structR $ {Panax Notoginseng intx, y; -}r[n*n/2]; the + BOOLCMP (R a,r B) A { the if(a.x<b.x)return true; + if(A.X==B.X&&A.Y<B.Y)return true; - return false; $ } $ intLowbit (intx) - { - returnx& (-x); the } - voidUpdate (intXintc)Wuyi { the for(inti = x; i < N; i = i +lowbit (i)) - { WuT[i] = T[i] +C; - } About } $LL sum (intx) - { - intres =0 ; - for(inti = x; I >=1; i = i-lowbit (i)) A { +res = res +T[i]; the } - returnRes; $ } the intMain () the { the intT; theCin>>T; - LL ans; in intAa1 =0; the while(t--) the { Aboutmemset (T,0,sizeof(t)); theMemset (R,0,sizeof(R)); theAns =0 ; thecas++; +scanf" %d%d%d",&n,&m,&k); - for(inti =0; I < K; i + + ) the {Bayiscanf"%d%d",&r[i].x,&r[i].y); the } theSort (r,r+k,cmp); - for(inti =0; I < K; i + +)//The starting point is the same, not crossing . - { the //Update (r[i].x,1); the //if (r[i].x==r[i-1].x| | R[I].Y==R[I-1].Y) continue; theAns = ans +i-sum (R[I].Y);//find the inverse logarithm of y, understand this line of code well! the //cout<< "ans:" <<ans<<endl; -Update (R[I].Y,1); the } theprintf"Test Case%d:%lld\n", Cas,ans); the 94 } the return 0; the}
POJ 3067 Japan (tree-like array)