hdu 5517 Triple(二维树状数组)
Triple
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 388 Accepted Submission(s): 148
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).
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
which describe the multi-set A, where 1≤ai,bi≤105.
The third line contains 3×m nonnegative integers
corresponding to the m triples of integers in B, where 1≤ci,di≤103 and 1≤ei≤105.
/*
hdu 5517 Triple(二维树状数组) problem:
给你n个二元组<a,b>, m个三元组<c,d,e>. 如果d = e,那么<a,c,d>会组成一个新的三元组集合G.
问G中有多少个三元组在凸点.(没有其它三元组比它大) solve:
要注意去重. 因为要求没有其它三元组比它大. 如果同一个b有多个a,那么只需要取最大的即可.
然后通过排序可以解决第一位a. 剩下两位c,d则可以通过二维树状数组来维护是否是最大值.
三元组G中相同的合并. hhh-2016-08-31 20:06:36
*/
#pragma comment(linker,"/STACK:124000000,124000000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
#include <math.h>
#include <queue>
#include <set>
#include <map>
#define lson i<<1
#define rson i<<1|1
#define ll long long
#define clr(a,b) memset(a,b,sizeof(a))
#define scanfi(a) scanf("%d",&a)
#define scanfs(a) scanf("%s",a)
#define scanfl(a) scanf("%I64d",&a)
#define key_val ch[ch[root][1]][0]
#define inf 0x3f3f3f3f3f3f3f3f
using namespace std;
const ll mod = 1e9+7;
const int maxn = 100010;
const int maxx = 1050;
int a,b;
int to[maxn],have[maxn]; struct node
{
int a,b,c;
int w;
node(){}
node(int _a,int _b,int _c,int _w):a(_a),b(_b),c(_c),w(_w) {}
bool operator <(const node &t)const
{
if(a!= t.a)
return a < t.a;
else if(b != t.b)
return b < t.b;
else if(c != t.c)
return c < t.c;
}
node operator +(const node &t)const
{
return node(a,b,c,w+t.w);
}
bool operator ==(const node &t)const
{
return !(*this<t || t < *this);
}
};
ll s[maxx][maxx];
int lowbit(int x)
{
return x&(-x);
}
void add(int x,int y,ll val)
{
for(int i = x; i <= 1000; i+=lowbit(i))
for(int j = y; j <= 1000; j+=lowbit(j))
{
s[i][j] += val;
}
} ll sum(int x,int y)
{
ll cnt = 0;
for(int i = x; i > 0; i-=lowbit(i))
for(int j = y; j > 0; j-=lowbit(j))
{
cnt += s[i][j];
}
return cnt;
}
node tp[maxn];
int main()
{
int T,cas =1;
int c,d,e;
// freopen("in.txt","r",stdin);
scanfi(T);
while(T--)
{
int n,m;
clr(s,0),clr(to,0);
int Maxy = 0, Maxx = 0,cnt = 0;
scanfi(n),scanfi(m);
for(int i = 0; i < n; i++)
{
scanfi(a),scanfi(b);
if(a > to[b])to[b] = a,have[b] = 1;
else if(a == to[b])have[b] ++;
// cout << a[i] <<" " <<b[i] <<endl;
}
for(int i = 0; i < m; i++)
{
scanfi(c),scanfi(d),scanfi(e);
Maxx = max(Maxx,c);
Maxy = max(Maxy,d);
if(to[e])
tp[cnt++] = node(to[e],c,d,have[e]);
}
sort(tp,tp+cnt);
int tot = 0;
for(int i = 1;i < cnt;i++)
{
if(tp[i] == tp[tot])
{
tp[tot] = tp[tot] + tp[i];
}
else
{
tp[++tot] = tp[i];
}
}
ll ans = 0;
for(int i = tot;i >= 0;i--)
{
node t = tp[i];
// printf("%d%d%d %d\n",t.a,t.b,t.c,t.w);
int x = t.b,y = t.c;
int large = sum(1000,1000)-sum(x-1,1000)-sum(1000,y-1)+sum(x-1,y-1);
// if(t.a != last)
// large -= have;
if(large == 0)
ans = (ll)(ans+t.w);
add(x,y,1);
}
printf("Case #%d: %I64d\n",cas++,ans);
}
return 0;
} /*
1
3 4
2 7 2 7 2 7
1 4 7 2 3 7 3 2 7 4 1 7
*/
hdu 5517 Triple(二维树状数组)的更多相关文章
- HDU 5517 【二维树状数组///三维偏序问题】
题目链接:[http://acm.split.hdu.edu.cn/showproblem.php?pid=5517] 题意:定义multi_set A<a , d>,B<c , d ...
- HDU 5517---Triple(二维树状数组)
题目链接 Problem Description Given the finite multi-set A of n pairs of integers, an another finite mult ...
- HDU 4456(二维树状数组+坐标转换)
题目链接:Problem - 4456 看别人叙述看的心烦,于是我自己画了一张图. 上图. 上代码 #include <iostream> #include <cstdio> ...
- 【 HDU - 4456 】Crowd (二维树状数组、cdq分治)
BUPT2017 wintertraining(15) #5A HDU 4456 题意 给你一个n行n列的格子,一开始每个格子值都是0.有M个操作,p=1为第一种操作,给格子(x,y)增加z.p=2为 ...
- HDU 5465 Clarke and puzzle Nim游戏+二维树状数组
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5465 Clarke and puzzle Accepts: 42 Submissions: 26 ...
- hdu 2642 二维树状数组 单点更新区间查询 模板水题
Stars Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/65536 K (Java/Others) Total Subm ...
- hdu 2642二维树状数组 单点更新区间查询 模板题
二维树状数组 单点更新区间查询 模板 从零开始借鉴http://www.2cto.com/kf/201307/227488.html #include<stdio.h> #include& ...
- HDU1559 最大子矩阵 (二维树状数组)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1559 最大子矩阵 Time Limit: 30000/10000 MS (Java/Others) ...
- hdu6078 Wavel Sequence dp+二维树状数组
//#pragma comment(linker, "/STACK:102400000,102400000") /** 题目:hdu6078 Wavel Sequence 链接:h ...
随机推荐
- 实验四Java Android简易开发
实验准备 Android Studio下载 Android Studio安装 实验内容 Android Stuidio的安装测试 Android Stuidio的安装测试: 参考<Java和An ...
- Alpha冲刺博客合集
Alpha冲刺序列: Alpha冲刺Day1:Alpha No.1 Alpha冲刺Day2:Alpha No.2 Alpha冲刺Day3:Alpha No.3 Alpha冲刺Day4:Alpha No ...
- 网络1712--c语言字符数组作业总结..
---恢复内容开始--- 作业亮点 1.总体情况 1.大部分同学利用了流程图后,对于思路的理解有了提升. 2.很多同学在总结方面写的很不错,能够罗列问题贴出解决问题,我们能够看到你们的进步 2.作业发 ...
- 冲刺每日报告--Day1
敏捷冲刺每日报告--Day1 情况简介 由于李世钰同学出差了,周六才能回来.所以我们只能先写爬虫,封装代码提供接口等他回来调用. 任务进度 赵坤:编写了基本爬虫代码,目前能在国内有版权的B站.爱奇艺中 ...
- 2017-2018-1 1623 bug终结者 冲刺005
bug终结者 冲刺005 by 20162323 周楠 今日任务:理清游戏运行逻辑,GameView类为游戏核心代码 简要介绍 游戏中整个地图都是由数组组成 1.整个地图为16×16格,主要元素有墙. ...
- Python实现基于协程的异步爬虫
一.课程介绍 1. 课程来源 本课程核心部分来自<500 lines or less>项目,作者是来自 MongoDB 的工程师 A. Jesse Jiryu Davis 与 Python ...
- Windows Server2012 故障转移集群之动态仲裁(Dynamic Quorum)
本篇文章主要介绍Windows2012的故障转移集群一个新功能“动态仲裁”,默认该功能是开启的: 动态仲裁能在当前群集投票出现分歧的情况下取消某些节点的投票权限,比如偶数个节点的群集环境.仲裁见证和动 ...
- Python习题(第一课)
想了想其他的太简单了,还是不放了,剩三题吧. 一.完美立方 编写一个程序,对任给的正整数N (N≤100),寻找所有的四元组(a, b, c, d),使得a^3= b^3 + c^3 + d^3,其中 ...
- vue中一个dom元素可以绑定多个事件?
其实这个问题有多个解决方法的 这里提出两点 第一种 第二种 现在dom上绑定一个 然后在你的methods中直接调用 如果要传参数 这时候千万别忘记 原创 如需转载注明出处 谢谢
- 从同步阻塞聊到Java三种IO方式
本文总结自 https://zhuanlan.zhihu.com/p/34408883, https://www.zhihu.com/question/19732473中愚抄的回答, http://b ...