hdu5618
题解:
CDQ分治
三重分治
第一重排序
第二重CDQ
第三重树状数组
代码:
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
int n,m,c[N],dp[N],T;
struct node
{
int x,y,z,id;
}a[N],tmp[N];
struct Tree
{
int c[N];
inline int low(int x){return x&-x;}
inline void modify(int x){while (x<=N-)c[x]=,x+=low(x);}
inline void updata(int x){while (x<=N-)c[x]++,x+=low(x);}
inline void init(){memset(c,,sizeof c);}
inline int query(int x)
{
int ans=;
while (x)ans+=c[x],x-=low(x);
return ans;
}
}Tree;
inline int cmp(node x,node y)
{
if (x.x!=y.x)return x.x<y.x;
if (x.y!=y.y)return x.y<y.y;
return x.z<y.z;
}
inline int cmp1(node x,node y)
{
if (x.y!=y.y)return x.y<y.y;
return x.z<y.z;
}
inline void solve(int l,int r)
{
if (l==r)return;
int m=(l+r)>>;
solve(l,m);
for (int i=l;i<=r;i++)tmp[i]=a[i];
sort(tmp+l,tmp+m+,cmp1);
sort(tmp+m+,tmp+r+,cmp1);
int pl=l;
for (int i=m+;i<=r;i++)
{
while (pl<=m&&tmp[pl].y<=tmp[i].y)
{
Tree.updata(tmp[pl].z);
pl++;
}
dp[tmp[i].id]+=Tree.query(tmp[i].z);
}
for (int i=l;i<=m;i++)Tree.modify(tmp[i].z);
solve(m+,r);
}
inline int read()
{
int x=;char c;
for (;c<''||c>'';c=getchar());
for (;c>=''&&c<='';c=getchar())x=x*+c-;
return x;
}
inline void write(int x)
{
if (x>=)write(x/);
putchar(x%+);
}
int main()
{
scanf("%d",&T);
while (T--)
{
scanf("%d",&n);
for (int i=;i<=n;i++)
{
a[i].x=read();
a[i].y=read();
a[i].z=read();
a[i].id=i;
}
sort(a+,a+n+,cmp);
memset(dp,,sizeof dp);
Tree.init();
solve(,n);
for (int i=n-;i;i--)
if (a[i].x==a[i+].x&&a[i].y==a[i+].y&&a[i].z==a[i+].z)
dp[a[i].id]=dp[a[i+].id];
for (int i=;i<=n;i++)write(dp[i]),puts("");
}
}
hdu5618的更多相关文章
- HDU5618 & CDQ分治
Description: 三维数点 Solution: 第一道cdq分治...感觉还是很显然的虽然题目不能再傻逼了... Code: /*=============================== ...
- HDU5618 Jam's problem again
CDQ分治模板题 #include<cstdio> #include<cctype> #include<algorithm> #include<cstring ...
- hdu5618 (三维偏序,cdq分治)
给定空间中的n个点,问每个点有多少个点小于等于自己. 先来分析简单的二维的情况,那么只要将x坐标排序,那么这样的问题就可以划分为两个子问题,,这样的分治有一个特点,即前一个子问题的解决是独立的,而后一 ...
- hdu5618(cdq分治求三维偏序)
题意:给n(n<=100000)个点,坐标为(xi,yi,zi)(1<=xi,yi,zi<=100000),定义一个点A比一个点B小,当且仅当xA<=xB,yA<=yB, ...
- HDU5618 Jam's problem again CDQ分治
Jam's problem again CDQ分治 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5618 题意: \[ 有n 个元素,第 i 个元素有 ...
随机推荐
- vue - 计算属性、表单输入绑定
计算属性 computed:{} <!DOCTYPE html> <html> <head> <title></title> </he ...
- android 错误收集
2. is not translated in Eclipse > Preference > Android > Lint Error Checking的Correctness: M ...
- 002-spring cache 基于声明式注解的缓存-02-CachePut、CacheEvict、Caching、CacheConfig、EnableCaching、自定义
1.2.CachePut annotation 在支持Spring Cache的环境下,对于使用@Cacheable标注的方法,Spring在每次执行前都会检查Cache中是否存在相同key的缓存元素 ...
- rtcp多媒体控制协议应用
rtcp package send/recv demo main.c #include <stdio.h> #include <rtp.h> #include <rtcp ...
- addslashes — 使用反斜线引用字符串
返回字符串,该字符串为了数据库查询语句等的需要在某些字符前加上了反斜线.这些字符是单引号(').双引号(").反斜线(\)与 NUL( NULL 字符). 一个使用 addslashes() ...
- python中的shallow copy 与 deep copy
今天在写代码的时候遇到一个奇葩的问题,问题描述如下: 代码中声明了一个list,将list作为参数传入了function1()中,在function1()中对list进行了del()即删除了一个元素. ...
- centos6 pip install python-ldap报错
error: Setup script exited with error: command 'gcc' failed with exit status 1 解决方法: 原因是版本不兼容,centos ...
- python 手动遍历迭代器
想遍历一个可迭代对象中的所有元素,但是却不想使用for 循环 为了手动的遍历可迭代对象,使用next() 函数并在代码中捕获StopIteration 异常.比如,下面的例子手动读取一个文件中的所有行 ...
- ubuntu 中启动SDK manager
Android SDK安装后,目录结构如下: root@localhost:/home/ranxf/Android/Sdk/android-sdk-linux# ll 总用量 drwxrwxr-x r ...
- 【运维技术】CentOS7上从零开始安装LAMP安装织梦DedeCMS教程
前期准备数据 centos7 系统 安装 appache httpd # 更新httpd yum update httpd # 安装httpd yum install -y httpd # 启动服务 ...