首页 技术 正文
技术 2022年11月18日
0 收藏 620 点赞 4,508 浏览 1375 个字

链接:

https://www.luogu.org/problem/P3810

题意:

一个元素三个属性, x, y, z, 给定求f(b) = {ax <= bx, ay <= by, az <= bz}, a的数量, 求0-(n-1)个数有多少个点满足

思路:

三维偏序, CDQ分治, 听说过, 一直想学, 先写板子题, 二维偏序就属性减到连个,搞一下.

CDQ的思想就是先对第一维排序, 左边的可以给有变贡献, 在分治下去, 同时对第二维排序, 将可用的点的第三维用数据结构维护一下, 挨个统计.

代码:

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5+10;struct Node
{
int x, y, z;
int cnt;
int ans;
}a[MAXN], b[MAXN];int C[MAXN], Res[MAXN];
int n, k, cnt;bool CmpX(Node a, Node b)
{
if (a.x != b.x)
return a.x < b.x;
else if (a.y != b.y)
return a.y < b.y;
else
return a.z < b.z;
}bool CmpY(Node a, Node b)
{
if (a.y != b.y)
return a.y < b.y;
else
return a.z < b.z;
}int Lowbit(int x)
{
return x&(-x);
}void Update(int pos, int val)
{
while (pos <= k)
{
C[pos] += val;
pos += Lowbit(pos);
}
}int Query(int pos)
{
int ans = 0;
while (pos > 0)
{
ans += C[pos];
pos -= Lowbit(pos);
}
return ans;
}void CDQ(int l, int r)
{
if (l == r)//边界条件
return ;
int mid = (l+r)/2;
CDQ(l, mid);
CDQ(mid+1, r);
sort(a+l, a+mid+1, CmpY);
sort(a+mid+1, a+r+1, CmpY);
int i = l, j = mid+1;
while (j <= r)
{
while (i <= mid && a[j].y >= a[i].y)
Update(a[i].z, a[i].cnt), i++;
a[j].ans += Query(a[j].z);
j++;
}
for (int z = l;z < i;z++)
Update(a[z].z, -a[z].cnt);
}int main()
{
scanf("%d%d", &n, &k);
for (int i = 1;i <= n;i++)
scanf("%d%d%d", &b[i].x, &b[i].y, &b[i].z);
sort(b+1, b+1+n, CmpX);
a[1] = b[1];
a[1].cnt = 1;
cnt = 1;
for (int i = 2;i <= n;i++)
{
if (b[i].x != a[cnt].x || b[i].y != a[cnt].y || b[i].z != a[cnt].z)
a[++cnt] = b[i], a[cnt].cnt = 1;
else
a[cnt].cnt++;
}
CDQ(1, cnt);
for (int i = 1;i <= cnt;i++)
Res[a[i].ans+a[i].cnt-1] += a[i].cnt;
for (int i = 0;i < n;i++)
printf("%d\n", Res[i]); return 0;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,111
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,584
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,431
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,203
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,838
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,922