题目描述:

有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. LeetCode算法题-Magic Squares In Grid(Java实现)

    这是悦乐书的第326次更新,第349篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第196题(顺位题号是840).3 x 3魔方是一个3 x 3网格,填充了从1到9的不同 ...

  2. 【Linux开发】OpenCV在ARM-linux上的移植过程遇到的问题1---cvNamedWindow调用报错的问题

    问题描述: 这个实际上是最后一部的问题,将生成的共享库文件放入到了/usr/local/opencv-arm/lib下,并且设置了LD_LIBRARY_PATH中为/usr/local/opencv- ...

  3. python+selenium模拟鼠标操作

    from selenium.webdriver.common.action_chains import ActionChains #导入鼠标相关的包 ------------------------- ...

  4. python虚拟环境virtualenv创建与迁移

    1.安装virtualenv pip install virtualenv #(python2) pip3 install virtualenv #(python3) 2.创建venv virtual ...

  5. MySQL-快速入门(8)存储过程、存储函数

    1.存储过程 1>创建存储过程:create procedure create procedure sp_name ([in | out | inout] param_name type) [c ...

  6. java基础笔记(11)

    css 样式的设置主要有选择器+声明{}:声明里又分为属性和值: 注释代码:/*注释语句*/ 内联式:写在元素开始的标签里:例:<p style = "color:red;font-s ...

  7. 高性能迷你React框架anujs1.1.3发布

    anujs现在只差一个组件(mention)就完全支持阿里的antd UI库了.一共跑通346个测试, 应该是全世界最接近官方React的迷你框架了. 以后的工作就是把React16的一些新特性支持了 ...

  8. Xdex(百度版)脱壳工具基本原理

    [原创]Xdex(百度版)脱壳工具基本原理作 者: sherrydl时 间: 2015-12-13,10:52:45链 接: http://bbs.pediy.com/showthread.php?t ...

  9. spark复习笔记(1)

    使用spark实现work count ---------------------------------------------------- (1)用sc.textFile(" &quo ...

  10. JavaEE高级-Spring Data学习笔记

    Spring Data概述 - Spring Data : Spring 的一个子项目.用于简化数据库访问,支持NoSQL 和 关系数据存储.其主要目标是使数据库的访问变得方便快捷. - Spring ...