「luogu3810」陌上花开
「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」陌上花开的更多相关文章
- 「BZOJ」「3262」陌上花开
CDQ分治 WA :在solve时,对y.z排序以后,没有处理「y.z相同」的情况,也就是说可能(1,2,3)这个点被放到了(2,2,3)的后面,也就是统计答案在前,插入该点在后……也就没有统计到! ...
- 「译」JUnit 5 系列:条件测试
原文地址:http://blog.codefx.org/libraries/junit-5-conditions/ 原文日期:08, May, 2016 译文首发:Linesh 的博客:「译」JUni ...
- 「译」JUnit 5 系列:扩展模型(Extension Model)
原文地址:http://blog.codefx.org/design/architecture/junit-5-extension-model/ 原文日期:11, Apr, 2016 译文首发:Lin ...
- JavaScript OOP 之「创建对象」
工厂模式 工厂模式是软件工程领域一种广为人知的设计模式,这种模式抽象了创建具体对象的过程.工厂模式虽然解决了创建多个相似对象的问题,但却没有解决对象识别的问题. function createPers ...
- 「C++」理解智能指针
维基百科上面对于「智能指针」是这样描述的: 智能指针(英语:Smart pointer)是一种抽象的数据类型.在程序设计中,它通常是经由类型模板(class template)来实做,借由模板(tem ...
- 「JavaScript」四种跨域方式详解
超详细并且带 Demo 的 JavaScript 跨域指南来了! 本文基于你了解 JavaScript 的同源策略,并且了解使用跨域跨域的理由. 1. JSONP 首先要介绍的跨域方法必然是 JSON ...
- 「2014-5-31」Z-Stack - Modification of Zigbee Device Object for better network access management
写一份赏心悦目的工程文档,是很困难的事情.若想写得完善,不仅得用对工具(use the right tools),注重文笔,还得投入大把时间,真心是一件难度颇高的事情.但,若是真写好了,也是善莫大焉: ...
- 「2014-3-18」multi-pattern string match using aho-corasick
我是擅(倾)长(向)把一篇文章写成杂文的.毕竟,写博客记录生活点滴,比不得发 paper,要求字斟句酌八股结构到位:风格偏杂文一点,也是没人拒稿的.这么说来,arxiv 就好比是 paper 世界的博 ...
- 「2014-3-17」C pointer again …
记录一个比较基础的东东-- C 语言的指针,一直让人又爱又恨,爱它的人觉得它既灵活又强大,恨它的人觉得它太过于灵活太过于强大以至于容易将人绕晕.最早接触 C 语言,还是在刚进入大学的时候,算起来有好些 ...
随机推荐
- gitlab的搭建与汉化
gitlab的搭建:内存最好2G以上 yum -y install curl unzip policycoreutils git wget 安装相关依赖包 所有gitlab rpm包的 ...
- notepad++,vim驼峰命名与下划线的互相转换
notepad++,vim驼峰命名与下划线的互相转换 IDDAY_TIMEDAY_FULL_NAMEDAY_OF_WEEKYEAR_MONTHYREA_NAME 下滑线转驼峰 大写转小写 有这么些 ...
- java -jar命令运行jar包时指定外部依赖jar包 linxux or windows
前尘回顾: setup.bat [chenquan@hostuser tartest]$ cat ../setup.sh javac -encoding UTF-8 -Djava.ext.dirs=. ...
- VMware升级到15版本虚拟机黑屏的解决方法
1.启动VMware15虚拟机,在菜单栏找到:虚拟机→管理→更改硬件兼容性 2.打开该项,弹出更改硬件兼容性向导对话框,点 下一步,接下来把硬件兼容性改为Workstation 12.x 3.根据提 ...
- Centos610安装MVN
1.下载mav安装 下载免安装版上传linux cd /opt/maven mkdir repository cd apche-maven-3.3.9/conf vi settings.xml 设置 ...
- GCD: 求两数最大公因数算法【欧几里得法】原理的个人理解 (80%图片讲解!)
那么,求 a,b 的最大公因数就是求最大的,能均分a,b的块!
- JDK源码分析-HashMap
一.HashMap的内部属性 1.1 成员变量 1.1.1 size: HashMap包含的KV键值对的数量,也就是我们通常调用Map.size()方法的返回值 public int size() { ...
- 爬虫,工具 - Splash
What is it? Splash is a javascript rendering service. It's a lightweight web browser with an HTTP AP ...
- 引入C/C++动态库
[DllImport("SocketAPI.dll", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = t ...
- Java 数据脱敏 工具类
一.项目导入Apache的commons的Jar包. Jar包Maven下载地址:https://mvnrepository.com/artifact/org.apache.commons/commo ...