题意: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;
}