hdu5517 二维树状数组
题意是给了 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 二维树状数组的更多相关文章
- 二维树状数组 BZOJ 1452 [JSOI2009]Count
题目链接 裸二维树状数组 #include <bits/stdc++.h> const int N = 305; struct BIT_2D { int c[105][N][N], n, ...
- HDU1559 最大子矩阵 (二维树状数组)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1559 最大子矩阵 Time Limit: 30000/10000 MS (Java/Others) ...
- POJMatrix(二维树状数组)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 22058 Accepted: 8219 Descripti ...
- poj 1195:Mobile phones(二维树状数组,矩阵求和)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14489 Accepted: 6735 De ...
- 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 ...
- POJ 2155 Matrix(二维树状数组+区间更新单点求和)
题意:给你一个n*n的全0矩阵,每次有两个操作: C x1 y1 x2 y2:将(x1,y1)到(x2,y2)的矩阵全部值求反 Q x y:求出(x,y)位置的值 树状数组标准是求单点更新区间求和,但 ...
- [poj2155]Matrix(二维树状数组)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 25004 Accepted: 9261 Descripti ...
- POJ 2155 Matrix (二维树状数组)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 17224 Accepted: 6460 Descripti ...
- [POJ2155]Matrix(二维树状数组)
题目:http://poj.org/problem?id=2155 中文题意: 给你一个初始全部为0的n*n矩阵,有如下操作 1.C x1 y1 x2 y2 把矩形(x1,y1,x2,y2)上的数全部 ...
随机推荐
- 在Linux下使用gcc编译mesa文件报undefined reference to symbol 'sin@@GLIBC_2.2.5和DSO missing from command line两个错误的解决方案
一.概述 在Linux系统下使用gcc编译用C语言写的mesa的示例程序. 环境:Ubuntu Server 18.04.1 二.问题的出现 在Ubuntu下安装好mesa所需的库文件,将目标文件从g ...
- Html.Partial,Html.RenderPartial Html.Action,Html.RenderAction区别
@Html.Partial,@Html.RenderPartial 这两者的共同点都是在视图中去调用另外一个视图,区别是 Html.Partial 有返回值 ( MvcHtmlStrin ...
- C#中 Excel和其他文件类型的Content-Type/mime-type
C#中 Excel和其他文件类型的Content-Type/mime-type For BIFF .xls files application/vnd.ms-excel For Excel2007 a ...
- hibernate中的addEntity setResultTransformer的比较
如果使用原生sql语句进行query查询时,hibernate是不会自动把结果包装成实体的.所以要手动调用addEntity(Class class)等一系列方法. 如session.createSQ ...
- Mysql推荐使用规范(转)
一:基础规范 1.使用InnoDB存储引擎 支持事务.行级锁.并发性能更好.CPU及内存缓存页优化使得资源利用率更高 2.推荐使用utf8mb4字符集 无需转码,无乱码风险, 支持emoji表情以及部 ...
- 搜素表脚本.vbs
Set oFso = CreateObject("Scripting.FileSystemObject")dim path(30)dim name(30)'说明书表头有15列:补丁 ...
- git error: Your local changes to the following files would be overwritten by merge:xxxxxx ,Please commit your changes or stash them before you merge.的phpstorm解决办法
git报错 error: Your local changes to the following files would be overwritten by merge: .idea/encoding ...
- PXC 57 二进制安装
1.准备阶段 1.1 在三个节点上分别创建:用户组 用户组 目录 --用户组 用户组 #/usr/sbin/groupadd mysql #/usr/sbin/useradd -g mysql mys ...
- 修改Linux系统默认编辑器
修改ubuntu的默认编辑器: echo export EDITOR=/usr/bin/vim >> ~/.bashrc 故障过程: 修改过程: 强制断开连接,重新连接,修改默认编辑器:e ...
- Spring Security http标签的use-expressions="true"属性
如果声明为true,那么在access属性要用hasRole()这样写: <intercept-url pattern="/secure/extreme/**" access ...