Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 160    Accepted Submission(s): 72


Problem Description
Given the finite multi-set A of n pairs
of integers, an another finite multi-set B of m triples
of integers, we define the product of A and B as
multi-set

C=A∗B={⟨a,c,d⟩∣⟨a,b⟩∈A, ⟨c,d,e⟩∈B and b=e}

For each ⟨a,b,c⟩∈C,
its BETTER set is defined as

BETTERC(⟨a,b,c⟩)={⟨u,v,w⟩∈C∣⟨u,v,w⟩≠⟨a,b,c⟩, u≥a, v≥b, w≥c}

As a \textbf{multi-set} of triples, we define the TOP subset (as a multi-set as well) of C,
denoted by TOP(C),
as

TOP(C)={⟨a,b,c⟩∈C∣BETTERC(⟨a,b,c⟩)=∅}

You need to compute the size of TOP(C).
 

Input
The input contains several test cases. The first line of the input is a single integer t (1≤t≤10) which
is the number of test case. Then t test
cases follow.

Each test case contains three lines. The first line contains two integers n (1≤n≤105) and m (1≤m≤105) corresponding
to the size of A and B respectively.

The second line contains 2×n nonnegative
integers

a1,b1,a2,b2,⋯,an,bn

which describe the multi-set A,
where 1≤ai,bi≤105.

The third line contains 3×m nonnegative
integers

c1,d1,e1,c2,d2,e3,⋯,cm,dm,em

corresponding to the m triples
of integers in B,
where 1≤ci,di≤103 and 1≤ei≤105.

 

Output
For each test case, you should output the size of set TOP(C).
 

Sample Input

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
 

Sample Output

Case #1: 5
Case #2: 12
思路:这题可以用二维树状数组做,先对二元组按y关键字升序排列,对三元组按z关键字升序排列,找出二元组中y相同的情况下最大的x及其个数,然后依次乘上三元组形成新的三元组并放入map中,用map记录三元组即其个数,便于后面统计方案。然后删去不合法的三元组,可以先对其按x,y,z一二三关键字降序排列,然后依次循环,这样首先保证x是递减的,然后如果在它右上方有点,那么这个点就要删除(即y,z都大于等于它),可以用树状数组实现。
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
#define inf 99999999
#define maxn 100050
int first[maxn],last[maxn],cnt[maxn],maxnum[maxn];
struct node1{
int x,y;
}a[maxn]; struct node2{
int x,y,z;
}c[maxn]; bool cmp(node1 a,node1 b){
if(a.y==b.y)return a.x>b.x;
return a.y<b.y;
}
bool cmp1(node2 a,node2 b){
return a.z<b.z;
}
struct node{
int x,y,z;
}temp,temp2; bool operator<(node a,node b){
if(a.x==b.x){
if(a.y==b.y)return a.z>b.z;
return a.y>b.y;
}
return a.x>b.x;
} map<node,int>mp;
map<node,int>::iterator it; int b[1005][1005],pan[1006][1006];
int lowbit(int x){
return x&(-x);
}
void update(int x,int y,int num)
{
int i,j;
for(i=x;i<=1003;i+=lowbit(i)){
for(j=y;j<=1003;j+=lowbit(j)){
b[i][j]+=num;
}
}
} int getsum(int x,int y)
{
int num=0,i,j;
for(i=x;i>0;i-=lowbit(i)){
for(j=y;j>0;j-=lowbit(j)){
num+=b[i][j];
}
}
return num;
} int cal(int x,int y){
return getsum(1003,1003)-getsum(1003,y-1)-getsum(x-1,1003)+getsum(x-1,y-1);
} int main()
{
int n,m,i,j,T,d,e,f,t,maxx,num,cas=0;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++){
scanf("%d%d",&a[i].x,&a[i].y);
}
sort(a+1,a+n+1,cmp);
for(i=1;i<=m;i++){
scanf("%d%d%d",&c[i].x,&c[i].y,&c[i].z);
}
sort(c+1,c+m+1,cmp1);
memset(first,0,sizeof(first));
memset(last,0,sizeof(last));
t=c[1].z;
first[t]=1;
c[m+1].z=-1;
for(i=2;i<=m+1;i++){
if(c[i].z!=t ){
last[t]=i-1;
t=c[i].z;
first[t]=i;
}
}
memset(maxnum,-1,sizeof(maxnum));
memset(cnt,0,sizeof(cnt));
for(i=1;i<=n;i++){
if(maxnum[a[i].y ]==-1 ){
maxnum[a[i].y ]=a[i].x;
cnt[a[i].y ]=1;
}
else{
if(maxnum[a[i].y ]<a[i].x){
maxnum[a[i].y ]=a[i].x;
cnt[a[i].y ]=1;
}
else if(maxnum[a[i].y ]==a[i].x){
cnt[a[i].y ]++; } } }
mp.clear();
for(i=1;i<=10000;i++){
if(maxnum[i ]!=-1 && first[i ]!=0 ){
for(j=first[i ];j<=last[i ];j++){
temp.x=maxnum[i];temp.y=c[j].x;temp.z=c[j].y;
mp[temp]+=cnt[i];
}
}
}
memset(b,0,sizeof(b));
memset(pan,0,sizeof(pan));
int ans=0;
for(it=mp.begin();it!=mp.end();it++){
temp=it->first;
int y=temp.y;
int z=temp.z;
if(pan[y][z]==0 && cal(y,z)==0){
ans+=it->second;
}
pan[y][z]=1;
update(y,z,1);
}
cas++;
printf("Case #%d: %d\n",cas,ans);
}
return 0;
}

hdu517 Triple的更多相关文章

  1. 山东省第七届ACM省赛------Triple Nim

    Triple Nim Time Limit: 2000MS Memory limit: 65536K 题目描述 Alice and Bob are always playing all kinds o ...

  2. hdu 3908 Triple(组合计数、容斥原理)

    Triple Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others) Total Su ...

  3. hdu 5517 Triple(二维树状数组)

    Triple Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  4. Codeforces 1071 C - Triple Flips

    C - Triple Flips 思路: 小范围暴力 大范围递归构造 构造方法: solve(l, r) 表示使l 到 r 区间全变为0的方法 为了使反转次数小于等于n/3 + 12 我们只需要保证每 ...

  5. 【BZOJ3771】Triple(生成函数,多项式运算)

    [BZOJ3771]Triple(生成函数,多项式运算) 题面 有\(n\)个价值\(w\)不同的物品 可以任意选择\(1,2,3\)个组合在一起 输出能够组成的所有价值以及方案数. \(n,w< ...

  6. PAT 1009. Triple Inversions (35) 数状数组

    Given a list of N integers A1, A2, A3,...AN, there's a famous problem to count the number of inversi ...

  7. 【BZOJ 3771】 3771: Triple (FFT+容斥)

    3771: Triple Time Limit: 20 Sec  Memory Limit: 64 MBSubmit: 547  Solved: 307 Description 我们讲一个悲伤的故事. ...

  8. hihoCoder #1872 : Pythagorean triple

    此题是 2018 年 ICPC Asia Beijing Regional Contest 的 C 题. 题目大意 求斜边长度不超过 $n$($ n \le 10^9$) 的勾股数的数量.不计两直角边 ...

  9. bzoj 3771 Triple FFT 生成函数+容斥

    Triple Time Limit: 20 Sec  Memory Limit: 64 MBSubmit: 847  Solved: 482[Submit][Status][Discuss] Desc ...

随机推荐

  1. nginx: [emerg] bind() to 0.0.0.0:80 failed (10013:

    问题出现 今天在win10安装nginx时候,启动nginx.exe时在dos窗口出现了这个错误,特此记录一下. 解决方法 上面报错信息的意思大概是:0.0.0:80地址访问不被允许.可能是80端口号 ...

  2. Openstack Keystone 认证服务(四)

    Openstack Keystone 认证服务(四) keystone 的安装完全依赖ocata的源, 如果没有建议自己搭建. 否则用的源不对会产生各种奇葩问题. 创建keystone库和用户: ## ...

  3. Maven学习笔记之第一个Maven项目(Linux)

    Maven是Apache旗下的管理Java项目jar包的项目管理工具,有了它可以很方便构建和管理我们的Java项目,你不必在互联网上逐个查找你需要的第三方jar包,你只需在maven reposito ...

  4. 代码页(CodePage)列表

    代码页编号    国家地区或语言37                 IBM037    IBM EBCDIC (US-Canada)    437                 IBM437    ...

  5. 深度解读设备的“万能语言”HarmonyOS的分布式软总线能力

    摘要:本文分享鸿蒙分布式软总线,并对相关源代码进行解析,为在鸿蒙系统平台上工作的相关人员的信息参考和指导. 总线是一种内部结构,在计算机系统中,主机的各个部件通过总线相连,外部设备通过相应的接口电路再 ...

  6. 干电池升压5V,功耗10uA

    PW5100干电池升压5V芯片 输出电容: 所以为了减小输出的纹波,需要比较大的输出电容值.但是输出电容过大,就会使得系统的 反应时间过慢,成本也会增加.所以建议使用一个 22uF 的电容,或者两个 ...

  7. linux通过ntp同步时间

    1.安装服务 yum install ntp ##安装ntp服务,这个和ntpdate不一样哦,用这个比较好 systemctl start ntpd.service ###启动服务 systemct ...

  8. MySQL调优用户监控之show processlist

    简介 show processlist显示这台MySQL正在连接的用户: mysql> show processlist; +----+------+-----------+-------+-- ...

  9. RPC 框架要实现这个功能,我们可以使用泛化调用。那什么是泛化调用呢?我们带着这个问题,先学习下如何在没有接口的情况下进行 RPC 调用。

    RPC 框架要实现这个功能,我们可以使用泛化调用.那什么是泛化调用呢?我们带着这个问题,先学习下如何在没有接口的情况下进行 RPC 调用.

  10. goroutine 分析 协程的调度和执行顺序 并发写 run in the same address space 内存地址 闭包 存在两种并发 确定性 非确定性的 Go 的协程和通道理所当然的支持确定性的并发方式(

    package main import ( "fmt" "runtime" "sync" ) const N = 26 func main( ...