poj 3067 树状数组 Japan

题意:http://poj.org/problem?id=3067

        两排点,问有多少个焦点。

做题过程:

       乍看以为是图论呢,韦广说是树状数组。于是我就开始自己想,自己写。左边那一列点从下往上插(线统计与之相连的那个点之前有的和,再插),与同一点相连的先插下面大的那一点(这样才不会被另外一个点统计)。

       哎,刚开始以为在一个位置插了就不能再插了呢,还开了一个vis数组。后来画了个图知道不用了。但还是wa,结果是,又是一道我觉得不会超int的超了int。

/*
Pro: 0

Sol:

date:
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define maxn 1010
int t,n,m,k;
long long c[maxn],ans;
struct Edge{
    int s,t;
}edge[maxn * maxn];//边可能有很多条!
bool cmp(Edge a, Edge b){
    if(a.s == b.s) return a.t > b.t;
    return a.s > b.s;
}
void modify(int pos){
    while(pos <= n){
        c[pos] += 1;
        pos += (pos & -pos);
    }
}
long long  getsum(int pos){
    long long sum = 0;
    while(pos){
        sum += c[pos];
        pos -= (pos & -pos);
    }return sum;
}
int main(){
    scanf("%d",&t);
    for(int ca = 1; ca <= t; ca ++){
        memset(c,0,sizeof(c));  ans = 0;
        scanf("%d%d%d",&m,&n,&k);//
        if(n < m) swap(m,n);
        for(int i = 0; i < k; i ++)
            scanf("%d%d",&edge[i].s,&edge[i].t);
        sort(edge,edge + k,cmp);//从后往前找
        for(int i = 0; i < k ; i ++){
            ans += getsum(edge[i].t - 1);
            modify(edge[i].t);
        }
        printf("Test case %d: %I64d\n",ca,ans);
    }
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值