题意是给了 n个二元组 m个三元组, 二元组可以和三元组 合并生成3元组,合并条件是<a,b> 与<c,d,e>合并成 <a,c,d> 前提是 b==e,

如果存在组合 uwv 使得u>=a w>=c v>=d 并且uwv和acd不等  就说abc 不是最优的,求问最后又多少个组合是最优的 , 这个组合中是允许重复的

我们对于每个b只取最大的a,然后让这个最大的a去和相应的b,c进行组合,然后对于这样的三元组 为了省去判断和他相等的个数,我们直接将相同的元组合并到一起去,

然后枚举a求在 在矩阵C[b][c]右下边是否存在值如果存在显然这个就不是最优的,用二维树状数组解决这个问题

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <string.h>
using namespace std;
const int maxn=;
struct point{
int a,c,d,nu;
bool operator <(const point &rhs)const{
if(a!=rhs.a)return a<rhs.a;
if(c!=rhs.c)return c<rhs.c;
return d<rhs.d;
}
bool operator ==(const point &rhs)const{
return a==rhs.a&&c==rhs.c&&d==rhs.d;
}
}P[maxn];
int B[maxn];
int nu[maxn];
int C[][];
int Nc,Nd,numofC;
void init()
{
numofC=Nc=Nd=;
memset(B,,sizeof(B));
memset(nu,,sizeof(nu));
memset(C,,sizeof(C));
}
int lowbit(int x)
{
return x&(-x);
}
void add(int c,int d,int val)
{
for(int i=c; i<=Nc; i+=lowbit(i))
for(int j=d; j<=Nd; j+=lowbit(j))
C[i][j]+=val;
}
int sum(int c, int d)
{
int ans=;
for(int i=c; i>; i-=lowbit(i))
for(int j=d; j>; j-=lowbit(j))
ans+=C[i][j];
return ans;
}
int main()
{
int cas;
scanf("%d",&cas);
for(int cc=; cc<=cas; cc++)
{
int n,m;
scanf("%d%d",&n,&m);
init();
for(int i=; i<n; i++)
{
int a,b;
scanf("%d%d",&a,&b);
if(B[b]<a){ B[b]=a; nu[b]=;}
else if(B[b]==a) nu[b]++;
}
for(int i=; i<m; i++)
{
int c,d,e;
scanf("%d%d%d",&c,&d,&e);
if(nu[e]>)
{
point t;
t.a=B[e]; t.c=c; t.d=d; t.nu=nu[e];
P[numofC++]=t;
}
Nc=max(c,Nc); Nd=max(Nd,d);
}
sort(P,P+numofC);
int ge=;
for(int i=; i<numofC; i++)
if(P[i]==P[ge-])P[ge-].nu+=P[i].nu;
else P[ge++]=P[i];
numofC=ge;
int ans=;
ge=;
for(int i=numofC-; i>=; i--)
{
point t=P[i];
int s2=sum(t.c-,Nd);
int s3=sum(Nc,t.d-);
int s4=sum(t.c-,t.d-);
if(ge-s2-s3+s4 == ){
ans+=t.nu;
}
ge++;
add(t.c,t.d,);
}
printf("Case #%d: %d\n",cc,ans); }
return ;
}

hdu5517 二维树状数组的更多相关文章

  1. 二维树状数组 BZOJ 1452 [JSOI2009]Count

    题目链接 裸二维树状数组 #include <bits/stdc++.h> const int N = 305; struct BIT_2D { int c[105][N][N], n, ...

  2. HDU1559 最大子矩阵 (二维树状数组)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1559 最大子矩阵 Time Limit: 30000/10000 MS (Java/Others)  ...

  3. POJMatrix(二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 22058   Accepted: 8219 Descripti ...

  4. poj 1195:Mobile phones(二维树状数组,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14489   Accepted: 6735 De ...

  5. Codeforces Round #198 (Div. 1) D. Iahub and Xors 二维树状数组*

    D. Iahub and Xors   Iahub does not like background stories, so he'll tell you exactly what this prob ...

  6. POJ 2155 Matrix(二维树状数组+区间更新单点求和)

    题意:给你一个n*n的全0矩阵,每次有两个操作: C x1 y1 x2 y2:将(x1,y1)到(x2,y2)的矩阵全部值求反 Q x y:求出(x,y)位置的值 树状数组标准是求单点更新区间求和,但 ...

  7. [poj2155]Matrix(二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 25004   Accepted: 9261 Descripti ...

  8. POJ 2155 Matrix (二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17224   Accepted: 6460 Descripti ...

  9. [POJ2155]Matrix(二维树状数组)

    题目:http://poj.org/problem?id=2155 中文题意: 给你一个初始全部为0的n*n矩阵,有如下操作 1.C x1 y1 x2 y2 把矩形(x1,y1,x2,y2)上的数全部 ...

随机推荐

  1. c++ 条件变量

    .条件变量创建 静态创建:pthread_cond_t cond=PTHREAD_COND_INITIALIZER; 动态创建:pthread_cond _t cond; pthread_cond_i ...

  2. UE4/Unity3d 根据元数据自动生成与更新UI

    大家可能发现一些大佬讲UE4,首先都会讲类型系统,知道UE4会根据宏标记生成一些特定的内容,UE4几乎所有高级功能都离不开这些内容,一般来说,我们不会直接去使用它. 今天这个Demo内容希望能加深大家 ...

  3. Go的json解析:Marshal与Unmarshal

    https://blog.csdn.net/zxy_666/article/details/80173288 https://www.jianshu.com/p/98965b3ff638

  4. VSCode之快捷键和常用插件

    前言 介绍一下我在VSCode中常用的一些快捷方式: ctrl+上下箭头 上下滚动页面 Ctrl+Shift+K 删除某一行 Alt+ ↑ / ↓ 移动某一行 Shift+Alt + ↓ / ↑ 复制 ...

  5. Install Local SQL In Mac OS

    extends:http://www.cnblogs.com/maxinliang/p/3583702.html 一.安装 到MySQL官网上http://dev.mysql.com/download ...

  6. GO语言-基础语法:条件判断

    1. IF判断(aa.txt内容:asdfgh.bb.txt内容:12345) package main import ( "io/ioutil" "fmt" ...

  7. poj 2069

    唔. 这道题的火候比较巧妙. 我们是每次找到一个最远的点,然后向那个最远点逼近. 这显然非常合理. #include <cstdlib> #include <cmath> #i ...

  8. CString 成员函数用法

    参考文档:http://www.cnblogs.com/Caiqinghua/archive/2009/02/16/1391190.html CString的构造函数CString( );例:CStr ...

  9. elk之elasticsearch(二)

    一.下载安装包:注意版本统一 wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3.2.zip wge ...

  10. 关于微信里wx.getUserInfo获取用户信息都是拼音的转成中文方法

    加一个参数:lang:"zh_CN" 就可以了  1.  加在js里面 wx.getUserInfo({ lang:"zh_CN", success: func ...