HDU_5517_Triple
Triple
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1004 Accepted Submission(s): 356
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.
5 9
1 1 2 2 3 3 3 3 4 2
1 4 1 2 2 1 4 1 1 1 3 2 3 2 2 4 1 2 2 4 3 3 2 3 4 1 3
3 4
2 7 2 7 2 7
1 4 7 2 3 7 3 2 7 4 1 7
Case #2: 12
- 集合凸点
- 难点在于能否快速判定比当前三维数据(ai,ci,di)更大的点是否存在
- 首先能不能对原始数据做一次压缩呢?
- 看数据范围发现a,b,e的范围一致,c,d的范围一致,而c,d的范围只有1e3,是可以接受的
- 那么我们可以先对于有效点集P做一次排序,从大到小排,优先度分别是a,c,d,那么我们算是对第一维a的数据进行一次筛选,剩下的就是对于c和d这两维数据的判定
- 在一维数据中我们可以用线段树或树状数组的方式对于有限数据范围的数据进行RMQ操作,快速找出区间内max,min,sum。。。。
- 那么我们这里的算是一维RMQ的一个扩展
- 如果我们可以找出比当前结点大的点的个数就可以把题解决
- 那么这里就是一个二维数据的RMQ问题,询问区间内点点的数目
- 可以通过二维树状数组来实现
- 这里需要注意的一点是,普通二维树状数组在update的时候是从小到大维护自[0][0]点至[x][y]点整体矩阵的数据,因此update(x,y)应该分别对于大于x和y的坐标点进行更新,意思是update的(x,y)这个点的信息对于大于等于当前矩阵所维护的信息具有影响作用,但对小的点所维护的信息没有效用
- 这道题却和普通思想截然相反,update的点(x,y)对于比此点小的点具有效用,因此更新方向和原始方向刚好相反,对应的quary过程也是相反的
- 最后还要对点集去重,记录对应点出现次数
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <climits>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
typedef long long LL ;
typedef unsigned long long ULL ;
const int maxn = 1e5 + ;
const int inf = 0x3f3f3f3f ;
const int npos = - ;
const int mod = 1e9 + ;
const int mxx = + ;
const double eps = 1e- ;
const double PI = acos(-1.0) ; struct node{
int a, c, d, cnt;
bool operator < (const node &r)const{
if(a!=r.a) return a>r.a;
else if(c!=r.c) return c>r.c;
else return d>r.d;
}
bool operator == (const node &r)const{
return (a==r.a)&&(c==r.c)&&(d==r.d);
}
};
node e[maxn];
int T, n, m, u, v, w, cnt, tot;
int a[maxn], c[maxn], d[+][+];
int lowbit(int x){
return x&(-x);
}
void update(int x, int y, int z){
for(int i=x;i>;i-=lowbit(i))
for(int j=y;j>;j-=lowbit(j))
d[i][j]+=z;
}
int quary(int x, int y){
int res=;
for(int i=x;i<=1e3;i+=lowbit(i))
for(int j=y;j<=1e3;j+=lowbit(j))
res+=d[i][j];
return res;
}
int main(){
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
while(~scanf("%d",&T)){
for(int kase=;kase<=T;kase++){
cnt=;
tot=;
memset(a,,sizeof(a));
memset(c,,sizeof(c));
memset(d,,sizeof(d));
scanf("%d %d",&n,&m);
for(int i=;i<=n;i++){
scanf("%d %d",&u,&v);
if(a[v]<u)
a[v]=u, c[v]=;
else if(a[v]==u)
c[v]++;
}
for(int i=;i<=m;i++){
scanf("%d %d %d",&u,&v,&w);
if(a[w])
e[cnt++]=(node){a[w],u,v,c[w]};
}
sort(e,e+cnt);
for(int i=;i<cnt;i++)
if(e[tot]==e[i])
e[tot].cnt+=e[i].cnt;
else
e[++tot]=e[i];
LL ans=0LL;
for(int i=;i<=tot;i++){
if(!quary(e[i].c,e[i].d))
ans+=e[i].cnt;
update(e[i].c,e[i].d,);
}
printf("Case #%d: %lld\n",kase,ans);
}
}
return ;
}
HDU_5517_Triple的更多相关文章
随机推荐
- bson.errors.InvalidStringData: strings in documents must be valid UTF-8
场景: pymongo 查询数据库的时候报错. for gscode in GSList_StockPool_Mongo_MktStop: self._collection_flash.find({& ...
- ubuntu 系统网络突然"网络已禁用"
sudo service network-manager stop sudo rm /var/lib/NetworkManager/NetworkManager.state sudo servic ...
- (转)音频输出PCM与LPCM有什么不同
多声道LPCM:无损音轨原始存在格式,概念上等效于wave文件,并不需要运算解码,可直接输入功放进行DA转换,光纤和同轴接口只能传输2声道LPCM,多声道LPCM需要HDMI接口传输. PCM: ...
- jquery widgets 弹框
<div id='dialog' style="display:none;"> <div style="text-align:center;" ...
- 学习 TList 类的实现[1]
最近整理了一些函数列表, 算是一个宏观的安排; 等以后再碰到一些函数时就可以放置的更有次序一些. 我对函数与类的理解是: 函数是一个功能模块, 类是一个更强大的功能模块; Delphi 已经提供了很多 ...
- CreateEvent和SetEvent及WaitForSingleObject的使用方法
CreateEvent: 1.函数功能: 创建一个命名或匿名的事件对象 2.函数原型: HANDLE CreateEvent( LPSECURITY_ATTRIBUTES lpEventAttri ...
- BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第14章节--使用Office Services开发应用程序 WOPI和新的Office Web Apps Server
BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第14章节--使用Office Services开发应用程序 WOPI和新的Office Web Apps Server ...
- Java精选笔记_面向对象(构造方法、this关键字、static关键字、内部类)
构造方法constructor构造器 构造方法的定义 [修饰符] 类名 (形式参数列表){ //语句 } 构造器用于构造该类的实例.作用:用来初始化对象!一般由系统在创建对象(即类的 ...
- java中被遗忘的native关键字
我是无意间看见JNI( java调用动态链接库dll )这块的东西. 所有记下来:本地声明方法 装载完成dll文件后,将使用的方法用native关键字声明. public native static ...
- INSTALL_FAILED_INVALID_APK
在项目中无意中把APP只写成了 xxx 没有xxx.xxx.xxx 掉坑里了,找了好久,给大家提不醒