Triple
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1127 Accepted Submission(s): 403
C=A∗B
For each ⟨a,b,c⟩∈C
BETTER
As a \textbf{multi-set} of triples, we define the TOP subset (as a multi-set as well) of C
TOP(C)={⟨a,b,c⟩∈C∣BETTER
You need to compute the size of TOP(C)
Each test case contains three lines. The first line contains two integers n (1≤n≤10
The second line contains 2×n
which describe the multi-set A
The third line contains 3×m
corresponding to the m
2 5 9 1 1 2 2 3 3 3 3 4 2 1 4 1 2 2 1 4 1 1 1 3 2 3 2 2 4 1 2 2 4 3 3 2 3 4 1 3 3 4 2 7 2 7 2 7 1 4 7 2 3 7 3 2 7 4 1 7
Case #1: 5 Case #2: 12
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int a[100005];
int cnt[100005];
int tr[1005][1005];
int lowbit(int i)
{
return i&(-i);
}
void update(int x,int y,int n)
{
for(int i=x;i<=n;i+=lowbit(i))
{
for(int j=y;j<=n;j+=lowbit(j))
{
tr[i][j]++;
}
}
}
int query(int x,int y)
{
int sum=0;
for(int i=x;i>0;i-=lowbit(i))
{
for(int j=y;j>0;j-=lowbit(j))
{
sum+=tr[i][j];
}
}
return sum;
}
struct node
{
int a,b,c,cnt;
node()
{
cnt=0;
}
}q[100005];
bool cmp(node a,node b)
{
if(a.a!=b.a)
return a.a<b.a;
else if(a.b!=b.b)
return a.b<b.b;
else
return a.c<b.c;
}
int main()
{
int t,n,m,x,y,z,cas=1;
scanf("%d",&t);
while(t--)
{
memset(a,0,sizeof(a));
memset(cnt,0,sizeof(cnt));
memset(tr,0,sizeof(tr));
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
scanf("%d%d",&x,&y);
if(a[y]==0)
{
a[y]=x;
cnt[x]=1;
}
else
{
if(x>a[y])
{
a[y]=x;
cnt[x]=1;
}
else if(x==a[y])
cnt[x]++;
}
}
int p=0;
for(int i=1;i<=m;i++)
{
scanf("%d%d%d",&x,&y,&z);
if(cnt[a[z]]==0)
continue;
else
{
q[p].a=a[z];
q[p].b=x;
q[p].c=y;
q[p].cnt=cnt[a[z]];
p++;
}
}
sort(q,q+p,cmp);
int k=0;
for(int i=1;i<p;i++)
{
if(q[k].a==q[i].a&&q[k].b==q[i].b&&q[k].c==q[i].c)
{
q[k].cnt+=q[i].cnt;
}
else
{
q[++k]=q[i];
}
}
int ans=0;
for(int i=k;i>=0;i--)
{
int num=query(1001,1001)-query(1001,q[i].c-1)-query(q[i].b-1,1001)+query(q[i].b-1,q[i].c-1);
if(num==0) ans+=q[i].cnt;
update(q[i].b,q[i].c,1001);
}
printf("Case #%d: %d\n",cas++,ans);
}
return 0;
}
407



被折叠的 条评论
为什么被折叠?



