#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
#define clr(x) memset(x,0,sizeof(x))
#define INF 0x1f1f1f1f
int cal[1111*1111];//树状数组用
int lowbit(int x) {return x&(-x);}
int getsum(int x)
{
int s=0;
for(;x>0;x-=lowbit(x)) s+=cal[x];
return s;
}
void update(int x,int value)
{
for(;x<=1111*1111;x+=lowbit(x)) cal[x]+=value;
}
struct node
{
int x,y;
}q[1111*1111];
int cmp(struct node a,struct node b)
{
if(a.x==b.x)return a.y<b.y;
return a.x<b.x;
}
int main()
{
int n,m,i,f,k,ca=1;
long long res;
scanf("%d",&f);
while(f--)
{
res=0;
clr(cal);
scanf("%d%d%d",&n,&m,&k);
for(i=1;i<=k;i++)
scanf("%d%d",&q[i].x,&q[i].y);
sort(q+1,q+k+1,cmp);
for(i=1;i<=k;i++)
{
update(q[i].y,1);
res=res+(i-getsum(q[i].y));
}
printf("Test case %d: %lld\n",ca++,res);
}
return 0;
}
poj3067 逆序数 (裸)
最新推荐文章于 2019-08-09 08:51:54 发布