题意是给了 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. SpringBoot系统列 1 - HelloWorld!

    学习SpringBoot系统列之HelloWorld! 1.新建一个Maven项目 2.添加POM配置 <parent> <groupId>org.springframewor ...

  2. AT&T汇编指令

    GAS中每个操作都是有一个字符的后缀,表明操作数的大小. C声明 GAS后缀 大小(字节) char b 1 short w 2 (unsigned) int / long / char* l 4 f ...

  3. python3 使用ldap3来作为django认证后台

    首先先使用ldap3测试ldap服务是否正常 我们先要拿到dc的数据,以及连接ldap的密码,还有搜索的字段(search_filter), 一般来说search_filter 这个是从负责ldap运 ...

  4. zookeeper使用

    ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,它包含一个简单的原语集,分布式应用程序可以基于它实现同步服务,配置维护和命名服务等.Zookeeper是hadoop的一个子项目,其 ...

  5. Dynamic attention in tensorflow

    新代码在contrib\seq2seq\python\ops\attention_decoder_fn.py 和之前代码相比 不再采用conv的方式来计算乘,直接使用乘法和linear 给出了两种at ...

  6. 这样使用 GPU 渲染 CSS 动画(转)

    大多数人知道现代网络浏览器使用GPU来渲染部分网页,特别是具有动画的部分. 例如,使用transform属性的CSS动画看起来比使用left和top属性的动画更平滑. 但是如果你问,“我如何从GPU获 ...

  7. 关于 Java 中关于 数组的声明

    第一种方式:直接声明(只能在定义处使用!) int[] arr = {2, 3, 4, 5} 第二种方式:显式声明(用于各种情况) 比如方法返回值: public static int[] getAr ...

  8. P1002 过河卒

    题目描述 棋盘上A点有一个过河卒,需要走到目标B点.卒行走的规则:可以向下.或者向右.同时在棋盘上C点有一个对方的马,该马所在的点和所有跳跃一步可达的点称为对方马的控制点.因此称之为“马拦过河卒”. ...

  9. jQuery实现限制input框 textarea文本框输入字符数量的方法

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  10. Python学习之旅(三十)

    Python基础知识(29):virtualenv virtualenv:用来为一个应用创建一套隔离的Python运行环境 比如,现有两个Python项目,一个是Python2.7的一个是Python ...