//11584687	NKHelloWorld	3067	Accepted	2764K	485MS	C++	1186B	2013-05-11 14:37:10
//这道题可能存在重边,K可能很大,需要longlong才能过
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
int n,m,k;
ll tree[1100];
struct NODE
{
    int x,y;
}node[1000*1000];

bool cmp(NODE n1,NODE n2)
{
    if(n1.x == n2.x)
    {
        return n1.y < n2.y;
    }
    return n1.x < n2.x;
}

ll sum(int pos)
{
    ll ret = 0;
    while(pos > 0)
    {
        ret += tree[pos];
        pos -= (pos & -pos);
    }
    return ret;
}

void BITinsert(int pos ,int val)
{
    while(pos <= 1000)
    {
        tree[pos] += val;
        pos += (pos & -pos);
    }
}

int main()
{
    int T;
    scanf("%d",&T);
    for(int TT = 1; TT<=T;TT++)
    {
        memset(tree,0,sizeof(tree));
        scanf("%d%d%d",&n,&m,&k);
        for(int i=0;i<k;i++)
        {
            scanf("%d%d",&node[i].x,&node[i].y);
        }
        sort(node,node+k,cmp);

        ll ans = 0;
        for(int i=k-1;i>=0;i--)
        {
            if(node[i].y != 1)
            {
                ans += sum(node[i].y-1);
            }
            BITinsert(node[i].y,1);
        }

        printf("Test case %d: %lld\n",TT,ans);
    }
    return 0;
}
posted on 2013-05-11 15:05  NKHe!!oWor!d  阅读(264)  评论(0编辑  收藏  举报