POJ 3067 Japan (tree-like array)

Source: Internet
Author: User

Title Link: http://poj.org/problem?id=3067

Test instructions is: Japan has N cities in the east, from north to south numbered 1 2 3,,,n,m cities in the west, from north to south numbered 1 2,,,, M,k Highway will be built, one end of the highway in the west, one end in the east; ask how many intersections of highways, not including the city's endpoints.

First, the x is sorted from small to large, if X is the same and then y from small to large. Simulation can be found that the number of intersection points is the number of reverse order of each Y, the problem becomes the reverse order of how many, the tree array to solve on it.

Pay attention to the answer with Longlong.

1 //#pragma COMMENT (linker, "/stack:102400000,102400000")2#include <iostream>3#include <cstdio>4#include <cstring>5#include <algorithm>6 using namespacestd;7 Const intMAXN = 1e3 +5;8 typedef __int64 LL;9 intBIT[MAXN], m;Ten structData { One     intx, y; A     BOOL operator< (ConstData &cmp)Const{ -         if(x = =cmp.x) -             returnY <cmp.y; the         returnX <cmp.x; -     } -}A[MAXN *MAXN]; -  +InlinevoidAddinti) { -      for(; I <= m; i + = (I &-i)) +bit[i]++; A } at  - intSuminti) { -     intres =0; -      for(; I >=1; I-= (I &-i)) -Res + =Bit[i]; -     returnRes; in } -  to intMain () + { -     intT, N, K; thescanf"%d", &t); *      for(intCA =1; CA <= T; ca++) { $scanf" %d%d%d", &n, &m, &k);Panax Notoginsengmemset (bit,0,sizeof(bit)); -          for(inti =0; I < K; i++) { thescanf"%d%d", &a[i].x, &a[i].y); +         } ASort (A, A +k); theLL res =0; +          for(inti =0; I < K; i++) { -Res + = (LL) (I-sum (A[I].Y)); $ Add (a[i].y); $         } -printf"Test Case%d:", CA); -printf"%i64d\n", res); 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.