Skip to content

Instantly share code, notes, and snippets.

@ducphanduyagentp
Created November 2, 2014 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ducphanduyagentp/e5968c281d2ae53b65b2 to your computer and use it in GitHub Desktop.
Save ducphanduyagentp/e5968c281d2ae53b65b2 to your computer and use it in GitHub Desktop.
#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