传送门:https://www.luogu.org/problemnew/show/P3810

cdq分治的模板题,第一层外部排序,第二层cdq归并排序,这个时候不用考虑第一次的顺序,第三次用树状数组。

注意,不要用memset,用队列保存加上的值,最后在把加上的值减去就行了。

#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <cassert>
//#include <unordered_map>
/* ⊂_ヽ
  \\ Λ_Λ 来了老弟
   \('ㅅ')
    > ⌒ヽ
   /   へ\
   /  / \\
   レ ノ   ヽ_つ
  / /
  / /|
 ( (ヽ
 | |、\
 | 丿 \ ⌒)
 | |  ) /
'ノ )  Lノ */ using namespace std;
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//typedef __int128 bll;
typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int,pii> p3; //priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl '\n' #define boost ios::sync_with_stdio(false);cin.tie(0)
#define rep(a, b, c) for(int a = (b); a <= (c); ++ a)
#define max3(a,b,c) max(max(a,b), c);
#define min3(a,b,c) min(min(a,b), c); const ll oo = 1ll<<;
const ll mos = 0x7FFFFFFF; //
const ll nmos = 0x80000000; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //
const int mod = ;
const double esp = 1e-;
const double PI=acos(-1.0);
const double PHI=0.61803399; //黄金分割点
const double tPHI=0.38196601; template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
} inline void cmax(int &x,int y){if(x<y)x=y;}
inline void cmax(ll &x,ll y){if(x<y)x=y;}
inline void cmin(int &x,int y){if(x>y)x=y;}
inline void cmin(ll &x,ll y){if(x>y)x=y;}
#define MODmul(a, b) ((a*b >= mod) ? ((a*b)%mod + 2*mod) : (a*b))
#define MODadd(a, b) ((a+b >= mod) ? ((a+b)%mod + 2*mod) : (a+b)) /*-----------------------showtime----------------------*/
const int maxn = 1e5+;
struct node{
int x,y,z;
int id;
}a[maxn],b[maxn],tmp[maxn];
bool cmp(node a,node b){
if(a.x != b.x) return a.x < b.x;
if(a.y != b.y) return a.y < b.y;
else return a.z < b.z;
}
int cnt[maxn],ans[maxn]; int sum[maxn*];
int lowbit(int x){
return x & (-x);
}
void add(int x,int c){
while(x < maxn*){
sum[x] += c;
x += lowbit(x);
}
}
int getsum(int x){
int res = ;
while(x > ) {
res += sum[x];
x -= lowbit(x);
}
return res;
}
int lazy[maxn];
queue<int>que;
void cdq(int le,int ri){
int mid = (le + ri) >> ;
if(ri - le <= ) return ;
cdq(le, mid); cdq(mid+, ri); // memset(sum, 0, sizeof(sum)); int p = le, q = mid+;
int id = ;
while(p <= mid && q <= ri){
if(a[p].y <= a[q].y) {
add(a[p].z, lazy[a[p].id]);
que.push(p);
tmp[++id] = a[p++];
}
else {
cnt[a[q].id] += getsum(a[q].z);
tmp[++id] = a[q++];
}
}
while(p <= mid) tmp[++id] = a[p++];
while(q <= ri) {
cnt[a[q].id] += getsum(a[q].z);
tmp[++id] = a[q++];
}
while(!que.empty()){
int u = que.front(); que.pop();
add(a[u].z, -lazy[a[u].id]);
} for(int i=; i<=id; i++) a[i+le-] = tmp[i]; }
// int out[maxn];
map<p3,int>mp; int main(){
int n,k;
scanf("%d%d", &n, &k);
int tot = ;
rep(i, , n) {
int x, y, z;
scanf("%d%d%d", &x, &y, &z);
// read(x);read(y);read(z);
p3 tp = p3(x, pii(y, z));
if(mp.count(tp)) lazy[mp[tp]]++,cnt[mp[tp]]++;
else {
tot++;
a[tot].id = tot;
a[tot].x = x;
a[tot].y = y;
a[tot].z = z;
mp[tp] = tot;
lazy[tot] = ;
}
}
sort(a+, a++tot, cmp); cdq(, tot); rep(i, , tot) ans[cnt[a[i].id]] += lazy[a[i].id];
/*
rep(i, 1, n) {
out[a[i].id] = cnt[a[i].id];
}
rep(i, 1, n)
cout<<cnt[i]<<" ";
cout<<endl;
*/
rep(i, , n-) printf("%d\n", ans[i]);
return ;
}

P3810 【模板】三维偏序(陌上花开)cdq分治的更多相关文章

  1. BZOJ3262: 陌上花开(三维偏序,CDQ分治)

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

  2. HDU 5618 Jam's problem again(三维偏序,CDQ分治,树状数组,线段树)

    Jam's problem again Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  3. hdu5618 (三维偏序,cdq分治)

    给定空间中的n个点,问每个点有多少个点小于等于自己. 先来分析简单的二维的情况,那么只要将x坐标排序,那么这样的问题就可以划分为两个子问题,,这样的分治有一个特点,即前一个子问题的解决是独立的,而后一 ...

  4. P3810 陌上花开 CDQ分治

    陌上花开 CDQ分治 传送门:https://www.luogu.org/problemnew/show/P3810 题意: \[ 有n 个元素,第 i 个元素有 a_i. b_i. c_i 三个属性 ...

  5. 洛谷P3810 陌上花开 CDQ分治(三维偏序)

    好,这是一道三维偏序的模板题 当然没那么简单..... 首先谴责洛谷一下:可怜的陌上花开的题面被无情的消灭了: 这么好听的名字#(滑稽) 那么我们看了题面后就发现:这就是一个三维偏序.只不过ans不加 ...

  6. BZOJ 3262: 陌上花开 [CDQ分治 三维偏序]

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

  7. 【BZOJ-3262】陌上花开 CDQ分治(3维偏序)

    3262: 陌上花开 Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 1439  Solved: 648[Submit][Status][Discuss ...

  8. N维偏序:cdq分治

    cdq(陈丹琦)分治,是一种类似二分的算法.基本思想同分治: 递归,把大问题划分成若干个结构相同的子问题,直到(L==R): 处理左区间[L,mid]对右区间[mid+1,R]的影响: 合并. 它可以 ...

  9. bzoj3262陌上花开 cdq分治

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

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

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

随机推荐

  1. Python(简单图形和文件处理)编程

    Python确实是一门很简洁而且功能有强大的语言,我觉得开始学习很容易理解,说到熟练和精通还是不容易的,还需不断学习. 从最基础的语法学习,有些部分各种语言是相同的,让人很好理解.编程也是从最简单语法 ...

  2. 【Spring】The matching wildcard is strict……

    applicationContext.xml 文件抛出了这个异常信息. 解决方法: 需要在 namespace 后加上对应的 schemaLocation,如下所示: <?xml version ...

  3. 释放你的硬盘空间!——Windows 磁盘清理技巧

    引言 用了Windows系统的各位都知道,作为系统盘的C盘的空间总是一天比一天少.就拿本人的例子来说,自从安装了Win10,就发现,C盘从一开始的10几G占用,到现在慢慢变成了20G.30G….占用只 ...

  4. Java 性能优化(一)

    Java 性能调优(一) 1.衡量程序性能的标准 (1) 程序响应速度: (2) 内存占有情况: 2.程序调优措施 (1) 设计调优 设计调优处于所有调优手段 的上层,需要在软件开发之前进行.在软件开 ...

  5. Asp.Net Core 发布到 Docker(Linux Centos 虚拟机,使用Dockerfile)

    实践一下 Asp.Net Core (基于.net core 2.2)部署到Docker 一.准备工作: 1. 使用Virtualbox创建一个Centos系统的虚拟机,并安装docker和vim 2 ...

  6. QRCode生成二维码,jq QRCode生成二维码,QRCode生成电子名片

    [QRCode官网]http://phpqrcode.sourceforge.net/ PHP QRCode生成二维码 官网下载QRCode源码包,引入源码包中的 qrlib.php . <?p ...

  7. 让 CXK 来教你实现游戏中的帧动画(上)

    一款游戏除了基本功能之外,还需要给玩家更多视觉上的刺激,这个时候就需要用特效来装饰.本文就将介绍 Cocos Creator 的动画系统,除了标准的位移.旋转.缩放动画和序列帧动画以外,这套动画系统还 ...

  8. 8、JAVA中的用户输入(I/0交互过程)

    这里在数组的学习中用到了用户输入,也就是交互模式,日常的数据,不可能每一次都是程序员定义好的,终究需要用户与程序之间进行交互,机器等待用户输入,用户通过键盘输入所需数据(数据包括,字符,字串,数值等) ...

  9. S3 Select for Java 使用记录

    背景 后台基本使用 Amazon 的全家桶(EC2.DynamoDB.S3.Step Fuction 等等)构建.现在需要根据访问者的 IP 确定访问者的国家或地区. 已知: 访问者 IP 一个 ip ...

  10. 深入理解ES6之——代理和反射(proxy)

    通过调用new proxy()你可以创建一个代理来替代另一个对象(被称为目标),这个代理对目标对象进行了虚拟,因此该代理与该目标对象表面上可以被当做同一个对象来对待. 创建一个简单的代理 当你使用Pr ...