题意是给了 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. (笔记)一场由SD卡引发的灾难

    一场由SD卡引发的灾难   注:此文章转自“https://user.qzone.qq.com/63915185/blog/1512562541”.   Flash里面的数据在使用过程中莫名改变或不翼 ...

  2. tensorflow使用多个gpu训练

    关于多gpu训练,tf并没有给太多的学习资料,比较官方的只有:tensorflow-models/tutorials/image/cifar10/cifar10_multi_gpu_train.py ...

  3. 寄存器理解 及 X86汇编入门

    本文整理自多材料源,感谢原址分享,请查看末尾Url I, 汇编语言分类: 汇编语言和CPU息息相关,但是不能把汇编语言完全等同于CPU的机器指令.不同架构的CPU指令并不相同,如x86,powerpc ...

  4. Cuda9.1+cunn7.1+Tensorflow1.7-GUP

    Cuda9.1下载地址 cudnn下载  需要注册英伟达账号 cuda安装完成后默认的环境变量配置不对,CUDA_PATH是C:\Program Files\NVIDIA GPU Computing ...

  5. Linux 下执行Shell 脚本的方式

    Shell 脚本的执行方式通常有如下三种: (1)bash script-name 或者 sh script-name:(2)path/script-name或者./script-name:(3)so ...

  6. [Benchmark] Codeflaws: A Programming Competition Benchmark for Evaluating Automated Program Repair Tools

    Basic Information Publication: ICSE'17 Authors: Shin Hwei Tan, Jooyong Yi, Yulis, Sergey Mechtaev, A ...

  7. ubuntu 14.04升级python2

    http://blog.csdn.net/zahuopuboss/article/details/50927432

  8. cs231n(三) 误差反向传播

    摘要 本节将对反向传播进行直观的理解.反向传播是利用链式法则递归计算表达式的梯度的方法.理解反向传播过程及其精妙之处,对于理解.实现.设计和调试神经网络非常关键.反向求导的核心问题是:给定函数 $f( ...

  9. pandas replace 替换功能function

    list like replace method dict like replace method regex expression import pandas as pd import numpy ...

  10. E - Closest Common Ancestors

    Write a program that takes as input a rooted tree and a list of pairs of vertices. For each pair (u, ...