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. SQL Server查询当前连接数

    行数就是连接数,每一行是连接详情 SELECT * FROM [Master].[dbo].[SYSPROCESSES] WHERE [DBID] IN ( SELECT [DBID] FROM [M ...

  2. WPF TreeView绑定xaml的写法

    方法一 <Window x:Class="TreeViewDemo.MainWindow" xmlns="http://schemas.microsoft.com/ ...

  3. C# WebClient的使用

    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...

  4. Gralde 同步失败

    Gralde 同步失败 尝试了各种方法,至少我觉得常见的一些方法我都尝试了.但一直下载依赖失败 > Could not resolve all files for configuration ' ...

  5. PySide——Python图形化界面入门教程(一)

    PySide——Python图形化界面入门教程(一) ——基本部件和HelloWorld 翻译自:http://pythoncentral.io/intro-to-pysidepyqt-basic-w ...

  6. Linux下获取arm的交叉编译工具链

    转载请注明文章:Linux下获取arm的交叉编译工具链 出处:多客博图 这里介绍,Linux下获取arm的交叉编译工具链,比如arm-linux-gnueabihf-gcc.arm-linux-gne ...

  7. Android零基础入门第25节:最简单最常用的LinearLayout线性布局

    原文:Android零基础入门第25节:最简单最常用的LinearLayout线性布局 良好的布局设计对于UI界面至关重要,在前面也简单介绍过,目前Android中的布局主要有6种,创建的布局文件默认 ...

  8. volatile变量理解 via《Java并发编程实战》

    第3章:对象的共享 volatile关键字的理解 volatile变量,用来确保将变量的更行操作通知到其他线程.当变量申明为volatile类型后,编译器与运行时都会注意带这个变量时共享的,因此不会将 ...

  9. oracle利用透明网关访问mssql

    遇到一个客户,有个需求,想将mssql中的数据抽取到oracle中.经过上网查找,感觉gateway这个工具可以实现,因此就搭建实验环境进行测试.首先在oracle delivery上面下载对应的安装 ...

  10. UWP入门(九)-- 枚举和查询文件和文件夹

    原文:UWP入门(九)-- 枚举和查询文件和文件夹 核心 API 所在的命名空间: Windows.Storage Windows.Storage.Streams Windows.Storage.Pi ...