live writer 测试

//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;
}

转载于:https://www.cnblogs.com/nkhelloworld/archive/2013/05/11/3072790.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值