「luogu3810」陌上花开

传送门

三维偏序, \(\text{CDQ}\) 分治板子题。

判重的地方注意一下,别的就都是板子了。

参考代码:

#include <algorithm>
#include <cstdio>
#define rg register
#define file(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)
using namespace std;
template < class T > inline void read(T& s) {
s = 0; int f = 0; char c = getchar();
while ('0' > c || c > '9') f |= c == '-', c = getchar();
while ('0' <= c && c <= '9') s = s * 10 + c - 48, c = getchar();
s = f ? -s : s;
} const int _ = 1e5 + 5, __ = 2e5 + 5; int n, k, tr[__], ans[_]; inline int lb(int x) { return x & -x; } inline void update(int x, int v)
{ for (rg int i = x; i <= k; i += lb(i)) tr[i] += v; } inline int query(int x)
{ int res = 0; for (rg int i = x; i >= 1; i -= lb(i)) res += tr[i]; return res; } struct node { int a, b, c, f, w; } t[_], tt[_];
inline bool cmp(const node& x, const node& y)
{ return x.a != y.a ? x.a < y.a : (x.b != y.b ? x.b < y.b : x.c < y.c); } inline void CDQ(int l, int r) {
if (l == r) return ;
int mid = (l + r) >> 1;
CDQ(l, mid), CDQ(mid + 1, r);
int i = l, j = mid + 1, p = l;
while (i <= mid && j <= r) {
if (t[i].b <= t[j].b)
update(t[i].c, t[i].w), tt[p++] = t[i++];
else
t[j].f += query(t[j].c), tt[p++] = t[j++];
}
while (i <= mid) update(t[i].c, t[i].w), tt[p++] = t[i++];
while (j <= r) t[j].f += query(t[j].c), tt[p++] = t[j++];
for (rg int i = l; i <= mid; ++i) update(t[i].c, -t[i].w);
for (rg int i = l; i <= r; ++i) t[i] = tt[i];
} int main() {
read(n), read(k);
for (rg int i = 1; i <= n; ++i)
read(t[i].a), read(t[i].b), read(t[i].c), t[i].w = 1;
sort(t + 1, t + n + 1, cmp);
int cnt = 1;
for (rg int i = 2; i <= n; ++i) {
if (t[i].a == t[cnt].a && t[i].b == t[cnt].b && t[i].c == t[cnt].c) ++t[cnt].w;
else t[++cnt] = t[i];
}
CDQ(1, cnt);
for (rg int i = 1; i <= cnt; ++i) ans[t[i].f + t[i].w - 1] += t[i].w;
for (rg int d = 0; d < n; ++d) printf("%d\n", ans[d]);
return 0;
}

「luogu3810」陌上花开的更多相关文章

  1. 「BZOJ」「3262」陌上花开

    CDQ分治 WA :在solve时,对y.z排序以后,没有处理「y.z相同」的情况,也就是说可能(1,2,3)这个点被放到了(2,2,3)的后面,也就是统计答案在前,插入该点在后……也就没有统计到! ...

  2. 「译」JUnit 5 系列:条件测试

    原文地址:http://blog.codefx.org/libraries/junit-5-conditions/ 原文日期:08, May, 2016 译文首发:Linesh 的博客:「译」JUni ...

  3. 「译」JUnit 5 系列:扩展模型(Extension Model)

    原文地址:http://blog.codefx.org/design/architecture/junit-5-extension-model/ 原文日期:11, Apr, 2016 译文首发:Lin ...

  4. JavaScript OOP 之「创建对象」

    工厂模式 工厂模式是软件工程领域一种广为人知的设计模式,这种模式抽象了创建具体对象的过程.工厂模式虽然解决了创建多个相似对象的问题,但却没有解决对象识别的问题. function createPers ...

  5. 「C++」理解智能指针

    维基百科上面对于「智能指针」是这样描述的: 智能指针(英语:Smart pointer)是一种抽象的数据类型.在程序设计中,它通常是经由类型模板(class template)来实做,借由模板(tem ...

  6. 「JavaScript」四种跨域方式详解

    超详细并且带 Demo 的 JavaScript 跨域指南来了! 本文基于你了解 JavaScript 的同源策略,并且了解使用跨域跨域的理由. 1. JSONP 首先要介绍的跨域方法必然是 JSON ...

  7. 「2014-5-31」Z-Stack - Modification of Zigbee Device Object for better network access management

    写一份赏心悦目的工程文档,是很困难的事情.若想写得完善,不仅得用对工具(use the right tools),注重文笔,还得投入大把时间,真心是一件难度颇高的事情.但,若是真写好了,也是善莫大焉: ...

  8. 「2014-3-18」multi-pattern string match using aho-corasick

    我是擅(倾)长(向)把一篇文章写成杂文的.毕竟,写博客记录生活点滴,比不得发 paper,要求字斟句酌八股结构到位:风格偏杂文一点,也是没人拒稿的.这么说来,arxiv 就好比是 paper 世界的博 ...

  9. 「2014-3-17」C pointer again …

    记录一个比较基础的东东-- C 语言的指针,一直让人又爱又恨,爱它的人觉得它既灵活又强大,恨它的人觉得它太过于灵活太过于强大以至于容易将人绕晕.最早接触 C 语言,还是在刚进入大学的时候,算起来有好些 ...

随机推荐

  1. PHP加JS实现分片上传,断点续传

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"/> <title> ...

  2. 【PAT甲级】1075 PAT Judge (25 分)

    题意: 输入三个正整数N,K,M(N<=10000,K<=5,M<=100000),接着输入一行K个正整数表示该题满分,接着输入M行数据,每行包括学生的ID(五位整数1~N),题号和 ...

  3. HDU 2063 过山车(二分图 && 匈牙利 && 最小点覆盖)

    嗯... 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2063 这是一道很经典的匈牙利问题: 把男同学看成左边点,女同学看成右边点,如果两个同学愿意同 ...

  4. Java读文件夹

    使用JAVA读取文件夹中的多个文件 package hx.ReadFile; import java.io.FileNotFoundException; import java.io.IOExcept ...

  5. CSS制作二级菜单时,二级菜单与一级菜单不对齐

    效果如图: 部分代码如图: <li><a href="#" target="_blank">关于我们</a> <ul& ...

  6. JavaEE实战——XML文档DOM、SAX、STAX解析方式详解

    原 JavaEE实战--XML文档DOM.SAX.STAX解析方式详解 2016年06月22日 23:10:35 李春春_ 阅读数:3445 标签: DOMSAXSTAXJAXPXML Pull 更多 ...

  7. Mysql常用的sql语句

    替换某字段的字符串: UPDATE article SET content = replace(content, '解决', '解放') WHERE ID<5000; 清空数据库,id也置空: ...

  8. Cosmetic Bottles - Cosmetic Packaging: What Are The Characteristics Of Trends?

    There are certain differences in products, of which cosmetics are the most obvious. In addition to t ...

  9. python opencv:摄像头捕获图像

  10. ANSYS-APDL施加扭转载荷CERIG命令

    目录 1. 要求 2. ANSYS有限元分析 2.1 APDL建模 2.2 APDL施加载荷 2.3 APDL查看结果 3. 举一反三 1. 要求 一块0.8m*0.4m*0.04m厚的钢板,在板的两 ...