题目描述:

有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. Arm-linux-gcc-4.3.2安装步骤 (转)

    http://blog.chinaunix.net/uid-26119896-id-3302233.html 安装交叉编译工具链: 1.首先以root用户登入 2.复制arm-linux-gcc-4. ...

  2. 网络编程.iocp

    1.(20191212)查到的一些资料:java从 JDK7开始 引入AOI(即 NIO2).然后 实现 IOCP使用的是 AsynchronousChannelGroup.AsynchronousS ...

  3. 【Linux-设备树】.dtb文件的反汇编

    在使用设备树时我们将**.dts文件利用dtc编译器编译为**.dtb文件. 在已知**.dtb文件的情况下我们有两种方法可以得到dts源码: 方法一:使用fdtdump工具进行反汇编 使用命令:ro ...

  4. 洛谷 P1631 序列合并(优先队列)

    传送门 解题思路 首先读入a.b数组后,sort一遍(从小到大),然后把a[1]+b[1],a[2]+b[1],a[3]+b[1]……a[n]+b[1]全部加入一个优先队列q(小根堆). 然后从一到n ...

  5. 面向对象super 练习

    看代码写结果[如果有错误,则标注错误即可,并且假设程序报错可以继续执行] class Foo(object): a1 = 1 def __init__(self,num): self.num = nu ...

  6. 【算法入门】深度优先搜索(DFS)

    深度优先搜索(DFS) [算法入门] 1.前言深度优先搜索(缩写DFS)有点类似广度优先搜索,也是对一个连通图进行遍历的算法.它的思想是从一个顶点V0开始,沿着一条路一直走到底,如果发现不能到达目标解 ...

  7. 编写的Java第一个程序

    没什么好介绍的,嘻嘻 package head; public class ee { public static void main(String[] args) { System.out.print ...

  8. css控制文本内容显示省略号

    1,单行文字显示省略号 div{ width:200px; overflow:hideen; white-space:nowrap; text-overflow:ellipsis; } 2,多行文字显 ...

  9. windows下挂载NFS共享目录

    1.在打开或关闭Windows功能中,选择安装NFS客户端 2.在命令行中,输入“mount \\172.24.184.31\data x:\”,输入mount查看详细挂载参数(注意此时uid.gid ...

  10. [ZJOI2007]最大半连通子图(Tarjan,拓扑序DP)

    [ZJOI2007]最大半连通子图 题目描述 一个有向图G=(V,E)称为半连通的(Semi-Connected),如果满足:?u,v∈V,满足u→v或v→u,即对于图中任意两点u,v,存在一条u到v ...