# poj_3067 japan[The inverse number tree array or merge sort)

Source: Internet
Author: User
Tags cas

Portal: poj_3067

Title: N,m,k, left and right two columns, the number of the range of 1-n,1-m, and then to K-Link.

Sample Input

`13 4 41 42 33 23 1`

Sample Output

`Test Case 1:5`

Idea: Reverse order number

Code:

Tree-shaped Array version

`Block array #include<iostream> #include <cstring> #include <cmath> #include <cstdio> #include < algorithm> #include <string> #include <map> #include <vector> #include <queue> #define Lson L, M,rt<<1#define Rson m+1,r,rt<<1|1#define INF 0x3f3f3f3f#define PI acos ( -1.0) #define MEM (A, B) memset (A, B, sizeof a) #define READ_ freopen ("I.txt", "R", stdin) using namespace std;typedef long long ll;const int n=1010;int n,m,k;int C [N];struct node{int A, b;}    P[1000010];int CMP (node A,node b) {if (A.A==B.A) return a.b<b.b; return A.A&LT;B.A;} int lowbit (int x) {return x& (-X);}        void Add (int x,int v) {while (x<=m) {c[x]+=v;    X+=lowbit (x);    }}LL sum (int x) {LL ret=0;        while (x>0) {ret=ret+c[x];    X-=lowbit (x); } return ret;}    int main () {int T;    scanf ("%d", &t);        for (int cas=1;cas<=t;cas++) {mem (c,0);        scanf ("%d%d%d", &n,&m,&k); for (int i=0;i<k;i+ +) scanf ("%d%d", &p[i].a,&p[i].b);        Sort (p,p+k,cmp);        LL ans=0;            for (int i=0;i<k;i++) {Add (p[i].b,1);        Ans+=sum (M)-sum (P[I].B);    } printf ("Test Case%d:%i64d\n", Cas,ans); } return 0;}`

poj_3067 japan[The inverse number tree array or merge sort)

Related Keywords:

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.