http://acm.hdu.edu.cn/showproblem.php?pid=5618

题意:……

思路:和NEUOJ那题一样的。重新写了遍理解了一下,算作处理三维偏序的模板了。

 #include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
using namespace std;
#define INF 0x3f3f3f3f
#define N 100010
typedef long long LL;
struct node {
int x, y, z, id, f;
} p[N], s[N];
int ans[N], same[N], bit[N], gap; bool cmpx(const node &a, const node &b) { if(a.x != b.x) return a.x < b.x; if(a.y != b.y) return a.y < b.y; return a.z < b.z; }
bool cmpy(const node &a, const node &b) { if(a.y != b.y) return a.y < b.y; if(a.x != b.x) return a.x < b.x; return a.z < b.z; }
bool cmpid(const node &a, const node &b) { return a.id < b.id; }
bool check(node a, node b) { return a.x == b.x && a.y == b.y && a.z == b.z; } int lowbit(int x) { return x & (-x); } void update(int x, int w) { while(x <= gap) bit[x] += w, x += lowbit(x); } int query(int x) { int ans = ; while(x) ans += bit[x], x -= lowbit(x); return ans; } void CDQ(int l, int r) {
if(l == r) return ;
int m = (l + r) >> ;
CDQ(l, m); CDQ(m + , r);
int cnt = ;
// 标记是在左边还是右边
for(int i = l; i <= r; i++) s[++cnt] = p[i], s[cnt].f = i <= m ? : ;
sort(s + , s + + cnt, cmpy);
for(int i = ; i <= cnt; i++)
if(!s[i].f) update(s[i].z, );
else ans[s[i].id] += query(s[i].z);
for(int i = ; i <= cnt; i++)
if(!s[i].f) update(s[i].z, -);
} int main() {
int t, n;
scanf("%d", &t);
while(t--) {
scanf("%d", &n); gap = ;
for(int i = ; i <= n; i++) {
scanf("%d%d%d", &p[i].x, &p[i].y, &p[i].z);
p[i].id = i; if(p[i].z > gap) gap = p[i].z;
}
sort(p + , p + + n, cmpx);
// 离散化
for(int i = ; i <= n; ) {
int j = i + ;
while(j <= n && check(p[j], p[i])) j++;
while(i < j) same[p[i++].id] = p[j-].id;
}
for(int i = ; i <= n; i++) p[i].x = i;
memset(bit, , sizeof(bit));
memset(ans, , sizeof(ans));
CDQ(, n);
sort(p + , p + + n, cmpid);
for(int i = ; i <= n; i++) printf("%d\n", ans[same[i]]);
}
return ;
}

HDU 5618:Jam's problem again(CDQ分治+树状数组处理三维偏序)的更多相关文章

  1. HDU 5618 Jam's problem again CDQ分治 BC ROUND 70

    题意:给你1e5个点(x,y,z),对于每一个点询问有多少个点(x1,y1,z1)满足x1<=x&&y1<=y&&z1<=z 分析:(官方题解奉上)很 ...

  2. [BZOJ2225][SPOJ2371]LIS2 - Another Longest Increasing Subsequence Problem:CDQ分治+树状数组+DP

    分析 这回试了一下三级标题,不知道效果怎么样? 回到正题,二维最长上升子序列......嗯,我会树套树. 考虑\(CDQ\)分治,算法流程: 先递归进入左子区间. 将左,右子区间按\(x\)排序. 归 ...

  3. HDU 5618 Jam's problem again (cdq分治+BIT 或 树状数组套Treap)

    题意:给n个点,求每一个点的满足 x y z 都小于等于它的其他点的个数. 析:三维的,第一维直接排序就好按下标来,第二维按值来,第三维用数状数组维即可. 代码如下: cdq 分治: #pragma ...

  4. HDU - 5324:Boring Class (CDQ分治&树状数组&最小字典序)

    题意:给定N个组合,每个组合有a和b,现在求最长序列,满足a不升,b不降. 思路:三位偏序,CDQ分治.   但是没想到怎么输出最小字典序,我好菜啊. 最小字典序: 我们倒序CDQ分治,ans[i]表 ...

  5. 【BZOJ4553】[Tjoi2016&Heoi2016]序列 cdq分治+树状数组

    [BZOJ4553][Tjoi2016&Heoi2016]序列 Description 佳媛姐姐过生日的时候,她的小伙伴从某宝上买了一个有趣的玩具送给他.玩具上有一个数列,数列中某些项的值可能 ...

  6. BZOJ 1176 Mokia CDQ分治+树状数组

    1176: [Balkan2007]Mokia Time Limit: 30 Sec  Memory Limit: 162 MBSubmit: 1854  Solved: 821[Submit][St ...

  7. 【bzoj3262】陌上花开 CDQ分治+树状数组

    题目描述 有n朵花,每朵花有三个属性:花形(s).颜色(c).气味(m),又三个整数表示.现要对每朵花评级,一朵花的级别是它拥有的美丽能超过的花的数量.定义一朵花A比另一朵花B要美丽,当且仅当Sa&g ...

  8. 【bzoj2225】[Spoj 2371]Another Longest Increasing CDQ分治+树状数组

    题目描述 给定N个数对(xi, yi),求最长上升子序列的长度.上升序列定义为{(xi, yi)}满足对i<j有xi<xj且yi<yj. 样例输入 8 1 3 3 2 1 1 4 5 ...

  9. BZOJ 2683 简单题 cdq分治+树状数组

    题意:链接 **方法:**cdq分治+树状数组 解析: 首先对于这道题,看了范围之后.二维的数据结构是显然不能过的.于是我们可能会考虑把一维排序之后还有一位上数据结构什么的,然而cdq分治却可以非常好 ...

随机推荐

  1. Android手势识别的发展

    在播放器.与手势识别.所以,看看今天的我们Android手势识别. 首先,我们需要站在巨人的肩膀上.有些人举了个例子和说明. 第一章: http://www.2cto.com/kf/201110/10 ...

  2. MVC EF 导航属性

    @model IQueryable<EFExam.Models.CategoryProductViewModel>@{    Layout = null;}<!DOCTYPE htm ...

  3. ASP 用隐藏域解决Http无状态问题

    <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>    < ...

  4. WPF获取控件内部的ScrollViewer,并控制ScrollViewer操作

    //获取内部  ScrollViewer方法 public static T FindVisualChild<T>(DependencyObject obj) where T : Depe ...

  5. 数据绑定(四)使用DataContext作为Binding的Source

    原文:数据绑定(四)使用DataContext作为Binding的Source DataContext属性被定义在FrameworkElement类里,这个类是WPF控件的基类,这意味着所有WPF控件 ...

  6. SqlServer 使用脚本创建分发服务及事务复制的可更新订阅

    原文:SqlServer 使用脚本创建分发服务及事务复制的可更新订阅 [创建使用本地分发服务器] /************************[使用本地分发服务器配置发布]*********** ...

  7. 微信小程序实战之百思不得姐精简版

    原文:微信小程序实战之百思不得姐精简版 微信小程序基本组件和API已撸完,总归要回到正题的,花了大半天时间做了个精简版的百思不得姐,包括段子,图片,音频,视频,四个模块.这篇就带着大家简述下这个小的A ...

  8. Android动画基础——属性动画(Property Animation)

    本篇涉及例子下载:Github 本篇讲android 3.0引入的属性动画框架,上篇写视图动画View Animation时就说过ViewAnimation的缺点,那就是动画作用的是view本身的视觉 ...

  9. 装了VS2005再装IIS,结果出了些小问题 访问IIS元数据库失败

    版本信息: Microsoft .NET Framework 版本:2.0.50727.42; ASP.NET 版本:2.0.50727.42 装了VS2005再装IIS,结果出了些小问题访问IIS元 ...

  10. ThinkPHP 提供Auth 权限管理、支付宝、微信支付、阿里oss、友盟推送、融云即时通讯、云通讯短信、Email、Excel、PDF 等等

    多功能 THinkPHP 开源框架 项目简介:使用 THinkPHP 开发项目的过程中把一些常用的功能或者第三方 sdk 整合好,开源供亲们参考,如 Auth 权限管理.支付宝.微信支付.阿里oss. ...