#include <stdio.h>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=1005;
long long c[maxn+1];
struct point
{
int x,y;
} p[1000005];
inline int lowbit(int x)
{
return x&(-x);
}
void update(int x)
{
for(int i=x; i<=maxn; i+=lowbit(i))
c[i]+=1;
}
long long sum(int x)
{
long long ans=0;
for(int i=x; i>0; i-=lowbit(i))
ans+=c[i];
return ans;
}
int cmp(point a,point b)
{
if(a.x!=b.x) return a.x<b.x;
return a.y<b.y;
}
int main()
{
int t,n,m,k;
scanf("%d",&t);
int test=1;
while(t--)
{
memset(c,0,sizeof(c));
scanf("%d%d%d",&n,&m,&k);
for(int i=0; i<k; i++)
scanf("%d%d",&p[i].x,&p[i].y);
sort(p,p+k,cmp);
long long ans=0;
for(int i=0; i<k; i++)
{
update(p[i].y);
ans+=i+1-sum(p[i].y);
}
printf("Test case %d: %lld\n",test++,ans);
}
return 0;
}
POJ 3067 Japan
最新推荐文章于 2022-03-19 17:01:59 发布