题目描述:

有n朵花,每朵花有三个属性:花形(s)、颜色(c)、气味(m),又三个整数表示。现要对每朵花评级,一朵花的级别是它拥有的美丽能超过的花的数量。定义一朵花A比另一朵花B要美丽,当且仅当Sa>=Sb,Ca>=Cb,Ma>=Mb。显然,两朵花可能有同样的属性。需要统计出评出每个等级的花的数量。

输入:
第一行为N,K (1 <= N <= 100,000, 1 <= K <= 200,000 ), 分别表示花的数量和最大属性值。
以下N行,每行三个整数si, ci, mi (1 <= si, ci, mi <= K),表示第i朵花的属性

输出:

包含N行,分别表示评级为0...N-1的每级花的数量。

样例输入:
10 3
3 3 3
2 3 3
2 3 1
3 1 1
3 1 2
1 3 1
1 1 2
1 2 2
1 3 2
1 2 1

样例输出:
3
1
3
0
1
0
1
0
0
1

题解:

三维偏序问题。排序一维,cdq分治一维,最后一维用树状数组就可以啦~最后两维比起树套树,分治+树状数组果然好写得多~

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath> #ifdef WIN32
#define LL "%I64d"
#else
#define LL "%lld"
#endif #ifdef CT
#define debug(...) printf(__VA_ARGS__)
#define setfile()
#else
#define debug(...)
#define filename ""
#define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout);
#endif #define R register
#define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 15, stdin), S == T) ? EOF : *S++)
#define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
char B[1 << 15], *S = B, *T = B;
inline int FastIn()
{
R char ch; R int cnt = 0; R bool minus = 0;
while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
ch == '-' ? minus = 1 : cnt = ch - '0';
while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
return minus ? -cnt : cnt;
}
#define maxn 100010
struct Point
{
int x, y, z, ans, tim;
inline bool operator < (const Point &that) const
{
if (x != that.x) return x < that.x;
if (y != that.y) return y < that.y;
return z < that.z;
}
inline bool operator == (const Point &that) const
{
return x == that.x && y == that.y && z == that.z;
}
}p[maxn], t[maxn];
int ans[maxn], now, n, k;
#define maxm 200010
int bit[maxm], last[maxm];
#define lowbit(_x) ((_x) & -(_x))
inline void add(R int x, R int val)
{
for (; x <= k; x += lowbit(x))
{
if (last[x] != now)
bit[x] = 0;
bit[x] += val;
last[x] = now;
}
}
inline int query(R int x)
{
R int ret = 0;
for (; x; x -= lowbit(x))
{
if (last[x] == now) ret += bit[x];
}
return ret;
}
void cdq(R int left, R int right)
{
if (left == right) return;
R int mid = left + right >> 1;
cdq(left, mid);
cdq(mid + 1, right);
++now;
for (R int i = left, j = mid + 1; j <= right; ++j)
{
for (; i <= mid && p[i].y <= p[j].y; ++i)
add(p[i].z, p[i].tim);
p[j].ans += query(p[j].z);
}
R int i, j, kk = 0;
for (i = left, j = mid + 1; i <= mid && j <= right; )
{
if (p[i].y <= p[j].y)
t[kk++] = p[i++];
else
t[kk++] = p[j++];
}
for (; i <= mid; )
t[kk++] = p[i++];
for (; j <= right; )
t[kk++] = p[j++];
for (R int i = 0; i < kk; ++i)
p[left + i] = t[i];
}
int main()
{
// setfile();
n = FastIn(); k = FastIn();
for (R int i = 1; i <= n; ++i)
{
R int x = FastIn(), y = FastIn(), z = FastIn();
p[i] = (Point) {x, y, z, 0, 1};
}
std::sort(p + 1, p + n + 1);
R int cnt = 0;
for (R int i = 1; i <= n; ++i)
{
if (p[i] == p[i - 1])
p[cnt].tim++;
else p[++cnt] = p[i];
}
for(R int i = 1; i <= cnt; ++i) p[i].ans = p[i].tim - 1;
cdq(1, cnt);
for (R int i = 1; i <= cnt; ++i)
ans[p[i].ans] += p[i].tim;
for (R int i = 0; i < n; ++i) printf("%d\n",ans[i] );
return 0;
}
/*
5 3
2 2 2
1 1 1
1 1 1
1 1 1
2 2 2
*/

【bzoj3262】陌上花开的更多相关文章

  1. [BZOJ3262]陌上花开

    [BZOJ3262]陌上花开 试题描述 有n朵花,每朵花有三个属性:花形(s).颜色(c).气味(m),又三个整数表示.现要对每朵花评级,一朵花的级别是它拥有的美丽能超过的花的数量.定义一朵花A比另一 ...

  2. bzoj3262 陌上花开 cdq+树状数组

    [bzoj3262]陌上花开 Description 有n朵花,每朵花有三个属性:花形(s).颜色(c).气味(m),又三个整数表示.现要对每朵花评级,一朵花的级别是它拥有的美丽能超过的花的数量.定义 ...

  3. bzoj3262陌上花开 cdq分治

    3262: 陌上花开 Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 2794  Solved: 1250[Submit][Status][Discus ...

  4. BZOJ3262 陌上花开 —— 三维偏序 CDQ分治

    题目链接:https://vjudge.net/problem/HYSBZ-3262 3262: 陌上花开 Time Limit: 20 Sec  Memory Limit: 256 MBSubmit ...

  5. bzoj3262陌上花开 cdq分治入门题

    Description 有n朵花,每朵花有三个属性:花形(s).颜色(c).气味(m),又三个整数表示.现要对每朵花评级,一朵花的级别是它拥有的美丽能超过的花的数量.定义一朵花A比另一朵花B要美丽,当 ...

  6. bzoj3262: 陌上花开(cdq分治+树状数组)

    3262: 陌上花开 题目:传送门 题解: %%%cdq分治 很强大的一个暴力...感觉比分块高级多了 这道题目就是一个十分经典的三维偏序的例题: 一维直接暴力排序x 二维用csq维护y 三维用树状数 ...

  7. bzoj3262: 陌上花开(树套树)

    #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...

  8. [模板] CDQ分治&&BZOJ3262:陌上花开

    简介 CDQ分治是分治的一种, 可以看做归并排序的扩展, 利用离线将一些 \(O(n)\) 的暴力优化到 \(O(log n)\). 它可以用来顶替一些高级(log)数据结构等. 一般地, CDQ分治 ...

  9. [luogu3810][bzoj3262][陌上花开]

    题目链接 思路 听说可以CDQ分治,然后我不会,所以我写树套树 首先肯定先按照a拍个序.然后就成了在b,c这两个数组中查询了.用一个树状数组套treap来维护.当插入一个数的时候,就在树状数组的b这个 ...

  10. bzoj3262: 陌上花开(CDQ+树状数组处理三维偏序问题)

    题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=3262 题目大意:中文题目 具体思路:CDQ可以处理的问题,一共有三维空间,对于第一维我们 ...

随机推荐

  1. [DS+Algo] 004 栈、队列及其代码实现

    1. Stack FILO (FirstInLastOut) 的链表结构 在程序编译环境上使用较多 常用操作 push pop peek is_empty size Python 代码示例 class ...

  2. Windows netcat 的工具的简单使用

    1. 下载 https://eternallybored.org/misc/netcat/ 2. 将目录添加到环境变量 C:\Work\netcat 3. 简单实验 4. 查看说明 UPDATE // ...

  3. [19/09/18-星期三] Python中的序列

    一. # 第四章 序列(视频58-76) ## 列表(list) - 列表是Python中的一个对象 - 对象(object)就是内存中专门用来存储数据的一块区域 - 之前我们学习的对象,像数值,它只 ...

  4. BAT推荐免费下载JAVA转型大数据开发全链路教程(视频+源码)价值19880元

    如今随着环境的改变,物联网.AI.大数据.人工智能等,是未来的大趋势,而大数据是这些基石,万物互联,机器学习都是大数据应用场景! 为什么要学习大数据?我们JAVA到底要不要转型大数据? 好比问一个程序 ...

  5. 各类最新Asp .Net Core 项目和示例源码

    1.网站地址:http://www.freeboygirl.com2.网站Asp .Net Core 资料http://www.freeboygirl.com/blog/tag/asp%20net%2 ...

  6. 03: 使用docker搭建Harbor私有镜像仓库

    1.1 harbor介绍 1.Harbor简介 1. Harbor是一个用于存储和分发Docker镜像的企业级Registry服务器. 2. 镜像的存储harbor使用的是官方的docker regi ...

  7. switch使用--查询水果价格案例

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. http参数传递方式

    url传参 这种在各种method(get,post,delete,put)都能使用,解析速度快 body体中的参数 application/x-www-form-urlencoded 这应该是最常见 ...

  9. Mysql批量更新的一个坑-&allowMultiQueries=true允许批量更新

    前言        实际上,我们经常会遇到这样的需求,那就是利用Mybatis批量更新或者批量插入,但是,实际上即使Mybatis完美支持你的sql,你也得看看你说操作的数据库是否支持,而阿福,最近就 ...

  10. 执行rpm -ivh 时报错:error rpmdb BDB0113 Threadprocess 11690140458095421504 failed

    执行rpm -ivh 时报错:error rpmdb BDB0113 Threadprocess 11690140458095421504 failed 1.具体报错如下: [root@heyong ...