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<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)