题意:给你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. 去除C/C++程序代码中的注释

    最近搞软件著作权,去除代码空行和注释比较麻烦,想写个程序自动去除,去网上搜了下,发现有类似的程序,不过只有去除注释.鉴于word中可以去除空行(用^p^p替换^p),先用网上的代码,以后有时间写个完整 ...

  2. 同一台Windows机器中启动多个Memcached服务

    同一台Windows机器中启动多个Memcached服务 这就需要在一台机器上启动多个Memcached服务了. 假设Memcached在如下目录:C:\memcached\memcached.exe ...

  3. 【转载】test和cmp比较

    标 题:test和cmp一个很菜很基础的话题! 作 者: FTBirthday 时 间:2003/05/19 01:14am 链 接:http://bbs.pediy.com 看过破解教程,都知道te ...

  4. Hibernate4.1.4配置二级缓存EHCache步骤

    1.当然首先引入EHCache相关的jar包 这些包不需要另外下载,在Hibernate官方网站下载Hibernate4.1.7的压缩包(如:hibernate-release-4.1.7.Final ...

  5. leetcode4 Valid Palindrome回文数

    Valid Palindrome回文数 whowhoha@outlook.com Question: Given a string, determine if it is a palindrome, ...

  6. hdu 3631

    最短路  执行一遍 Floyd算法    比赛的时候没有想到, 用了优化的Dijkstra  超时到死 #include <cstdio> #include <cstring> ...

  7. spoj 24

    大数  #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> ...

  8. How to Cope with Deadlocks

    http://dev.mysql.com/doc/refman/5.0/en/innodb-deadlocks.html How to Cope with Deadlocks This section ...

  9. 【疯狂Java学习笔记】【第一章:Java语言概述】

    [学习笔记]1.Java与C#的异同:Java与C#的相同之处有很多,它们均摒弃了C++面向对象的多继承.宏定义.全局变量.全局函数.指针等等难以使用的机制,添加进了成熟的机制,如垃圾回收.接口等等. ...

  10. SQL四种语言:DDL,DML,DCL,TCL

    1.DDL(Data Definition Language)数据库定义语言statements are used to define the database structure or schema ...