Created
November 2, 2014 15:04
-
-
Save ducphanduyagentp/e5968c281d2ae53b65b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define f0(i,n) for(__typeof(n) i=0;i<n;i++) | |
#define rep(i,a,b) for(__typeof(b) i=a;i<=b;i++) | |
#define read(s) freopen(s , "r" ,stdin) | |
#define write(s) freopen(s , "w" , stdout) | |
#define BUG(x) cerr << #x << " = " << x << '\n' | |
using namespace std; | |
const int MAXN = 1003; | |
typedef long long ll; | |
ll BIT[MAXN+7]; | |
int N,M,K; | |
void update(int x,ll val){ for ( ; x <= M ; x += x & -x ) BIT[x] += val; } | |
ll get(int x){ | |
ll res = 0; | |
for ( ; x ; x -= x & -x ) res += BIT[x]; | |
return res; | |
} | |
typedef pair < int , int > ii; | |
int t,T; | |
ii k[MAXN*MAXN]; | |
void input(){ | |
scanf("%d %d %d" ,&N,&M,&K); | |
rep(i,1,K) scanf("%d %d" ,&k[i].first,&k[i].second); | |
sort(k+1,k+K+1); | |
if (t) memset(BIT,0,sizeof BIT); | |
ll res = 0; | |
for ( int i = K ; i ; i-- ){ | |
res += get(k[i].second-1); | |
update(k[i].second,1); | |
} | |
printf("Test case %d: %lld\n",t+1,res); | |
} | |
int main(){ | |
scanf("%d" ,&T); | |
for ( t = 0 ; t < T ; t ++ ) input(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment