题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5517
#include<bits/stdc++.h>
using namespace std;
#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define read(x,y) scanf("%d%d",&x,&y)
#define ll long long
#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int maxn =1e5+5;
const int mod=1e9+7;
/*
题目大意:数学题目题意比较绕口,
这道题的关键是如何去除重复点,和多余的点。
刚开始维护数据的时候想的贼复杂。。。
其实在构造三元组时当b,c确定时只要保留a的最大值就行,
因为在比其小的三元组内不能构成答案的贡献。
然后就是去重,这点相对容易,排完序再压缩下就行。
下面就是典型的二维树状数组计数问题了。
*/
struct node{
int x,y,z;
ll w;
bool operator<(const node& p) const
{
if(x==p.x)
{
if(y==p.y) return z<p.z;
return y<p.y;
}
return x<p.x;
}
bool operator==(const node& p) const
{
return x==p.x&&y==p.y&&z==p.z;
}
}jihe[maxn];
int tot=0;
///数据域
int n,m;
int mp[maxn],cp[maxn];
int x,y,z;
///二维树状数组
#define ub 1005
int tree[ub][ub];
int lowbit(int x)
{
return x&(-x);
}
void add(int x,int y,int d)
{
int tp=y;
while(x<ub)
{
for(int p=tp;p<ub;tree[x][p]+=d,p+=lowbit(p));
x+=lowbit(x);
}
}
int sum(int x,int y)
{
int ret=0,tp=y;
while(x)
{
for(int p=tp;p>0;ret+=tree[x][p],p-=lowbit(p));
x-=lowbit(x);
}
return ret;
}
int main()
{
int t;scanf("%d",&t);
for(int ca=1;ca<=t;ca++)
{
scanf("%d%d",&n,&m);
memset(tree,0,sizeof(tree));
memset(jihe,0,sizeof(jihe));
memset(mp,0,sizeof(mp));
for(int i=0;i<n;i++)
{
scanf("%d%d",&x,&y);
if(x>mp[y]) {mp[y]=x;cp[y]=0;}
if(x==mp[y]) cp[y]++;///记录数量
}
tot=0;
for(int i=0;i<m;i++)
{
scanf("%d%d%d",&x,&y,&z);
if(mp[z]) jihe[tot++]=node{mp[z],x,y,cp[z]};
}
sort(jihe,jihe+tot);
int N=0;
for(int i=1;i<tot;i++)
{
if(jihe[i]==jihe[N]) jihe[N].w+=jihe[i].w;///删去重复点
else jihe[++N]=jihe[i];
}
///构造出三元组了
ll ans=0;
for(int i=N;i>=0;i--)
{
ll ty=jihe[i].y,tz=jihe[i].z;
ll ret=sum(ub-1,ub-1)+sum(ty-1,tz-1)-sum(ub-1,tz-1)-sum(ty-1,ub-1);
if(ret==0) ans+=jihe[i].w;
add(ty,tz,1);
}
printf("Case #%d: %lld\n",ca,ans);
}
return 0;
}