题意:给你1e5个点(x,y,z),对于每一个点询问有多少个点(x1,y1,z1)满足x1<=x&&y1<=y&&z1<=z

分析:(官方题解奉上)很显然让你找(x,y,z)(x,y,z)都大于别的(x,y,z)(x,y,z),当然厉害的人可以用树套树水一下,但正解写的是CDQ分治,以xx为第一关键字排序,以yy为第二关键字来找,以zz为第三关键字建一个树状数组找就好了,当然等于的情况可以实现前做一下。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
using namespace std;
typedef long long LL;
const int maxn=1e5+;
struct BIT
{
int c[maxn];
void init()
{
memset(c,,sizeof(c));
}
int lowbit(int x)
{
return x&(-x);
}
void add(int x,int t)
{
while(x<=1e5)
{
c[x]+=t;
x+=lowbit(x);
}
}
int sum(int x)
{
int ans=;
while(x>)
{
ans+=c[x];
x-=lowbit(x);
}
return ans;
}
} bit;
struct Node
{
int x,y,z,id;
} o[maxn],tem[maxn];
bool cmp(Node a,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 cmp1(Node a,Node b)
{
return a.y<b.y;
}
int res[maxn];
void solve(int l,int r)
{
if(l==r)return;
int m=(l+r)>>;
for(int i=l; i<=r; ++i)
tem[i]=o[i];
sort(tem+l,tem+m+,cmp1);
sort(tem+m+,tem+r+,cmp1);
int cnt=l;
for(int i=m+; i<=r; ++i)
{
while(cnt<=m&&tem[cnt].y<=tem[i].y)bit.add(tem[cnt].z,),cnt++;
res[tem[i].id]+=bit.sum(tem[i].z);
}
for(int i=l; i<cnt; ++i)
bit.add(tem[i].z,-);
solve(l,m);
solve(m+,r);
}
int main()
{
int T,n;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
bit.init();
for(int i=; i<=n; ++i)
scanf("%d%d%d",&o[i].x,&o[i].y,&o[i].z),o[i].id=i;
sort(o+,o++n,cmp);
memset(res,,sizeof(res));
solve(,n);
for(int i=n-; i>; --i)
if(o[i].x==o[i+].x&&o[i].y==o[i+].y&&o[i].z==o[i+].z)
res[o[i].id]=res[o[i+].id];
for(int i=; i<=n; ++i)
printf("%d\n",res[i]);
}
return ;
}

HDU 5618 Jam's problem again CDQ分治 BC ROUND 70的更多相关文章

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

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

  2. cdq分治(hdu 5618 Jam's problem again[陌上花开]、CQOI 2011 动态逆序对、hdu 4742 Pinball Game、hdu 4456 Crowd、[HEOI2016/TJOI2016]序列、[NOI2007]货币兑换 )

    hdu 5618 Jam's problem again #include <bits/stdc++.h> #define MAXN 100010 using namespace std; ...

  3. HDU5618 Jam's problem again CDQ分治

    Jam's problem again CDQ分治 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5618 题意: \[ 有n 个元素,第 i 个元素有 ...

  4. HDU 5618 Jam's problem again(三维偏序,CDQ分治,树状数组,线段树)

    Jam's problem again Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  5. HDU 5618 Jam's problem again

    题意: 三维坐标,对于1个点,找出有多少个点,3个坐标都比该点小! Sample Input 1 4 10 4 7 10 6 6 8 2 5 7 3 10   Sample Output 1 1 0 ...

  6. hdu_5618_Jam's problem again(cdq分治+lowbit)

    题目链接:hdu_5618_Jam's problem again 题意: 给你n个点,每个点有一个坐标(x,y,z),找出有ans个点,3个坐标都比该点小,这个点的level就为ans,然后让你输出 ...

  7. HDU - 5730 :Shell Necklace(CDQ分治+FFT)

    Perhaps the sea‘s definition of a shell is the pearl. However, in my view, a shell necklace with n b ...

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

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

  9. SPOJ LIS2 - Another Longest Increasing Subsequence Problem(CDQ分治优化DP)

    题目链接  LIS2 经典的三维偏序问题. 考虑$cdq$分治. 不过这题的顺序应该是 $cdq(l, mid)$ $solve(l, r)$ $cdq(mid+1, r)$ 因为有个$DP$. #i ...

随机推荐

  1. iisapp appcmd

    C:\Windows\System32\inetsrv>appcmd list wp

  2. 自己利用jQuery实现的win8图标浮动更新

    在学校参加网页设计大赛时,由于美工设计的刚好是metro风格的(其实她们从来没有用过win8也没有了解过),而本人也很喜欢win8的界面,于是就做了一个metro风格的作品.虽然最终没能获奖,但是觉得 ...

  3. shell复习笔记----入门知识

    Unix 简史 UNIX 最初是由贝尔实验室(Bell Telephone Laborataries)的计算机科学研究中心开发的,第一版诞生于1970年--也就是在贝尔实验室退出Multics项目不久 ...

  4. 构建第一个Java程序

  5. [转]BluetoothDevice.getType()-一个常常被忽略了的函数。好用的不要不要的

    自动安卓发布了4.0版本的蓝牙协议之后,越来越多的开发者收到了各种针对于BLE蓝牙的开发需求. 而且有很多时候还需要兼容以前的3.0版本,给大家的开发带来了困扰,笔者也遇到了这样的问题,偶然间发现了g ...

  6. vncserver 添加用户

    1.在vncserver设置登录用户的信息   #vi /etc/sysconfig/vncservers   VNCSERVERS="1:root 2:wt" 此处添加用户   ...

  7. Hibernate缓存机制简述 (转)

    感谢:http://blog.csdn.net/ramln1989/article/details/5528445 ------------------------------------------ ...

  8. 解决VS如何同时打开两个工程(xp和win7)

    http://www.360doc.com/content/11/1020/00/7891073_157586269.shtml

  9. 利用手上的UI资源(附免费UI工具包)

    http://www.uisdc.com/how-to-use-ui-kits# 大家都知道,UI工具包里有很多好看的资源:比如按钮.滑块.面包屑.播放器.表单,甚至是一个"赞!" ...

  10. 对JAVA动态代理的理解

    叫动态代理就代表着有“静态代理”这回事. 而且,通常“动态”至少听着更NB一点. 关键就在于不明白啥叫“动”,这个得跟“静”比较下. 在我的理解,静态代理得自己声明一个类,实现跟被代理对象同样的接口. ...