裸的cdq, 没啥好说的, 要注意mid左边和mid右边的a相同的情况。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long
using namespace std; const int N = 5e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-; int n; struct node {
int a, b, c;
bool die;
} p[N], tmp[N]; bool cmpa(const node& x, const node& y) {
return x.a > y.a;
}
bool cmpb(const node& x, const node& y) {
return x.b > y.b;
} void cdq(int l, int r) {
if(l == r) return;
int mid = l + r >> ;
int v1 = p[mid].a, v2 = p[mid + ].a;
cdq(l, mid); cdq(mid + , r);
int mx = , mx2 = ;
for(int i = mid + , j = l; i <= r; i++) {
while(j <= mid && p[j].b > p[i].b) {
mx = max(mx, p[j].c);
if(p[j].a > v1) mx2 = max(mx2, p[j].c);
j++;
}
if(p[i].a == v1) {
if(mx2 > p[i].c) p[i].die = true;
} else {
if(mx > p[i].c) p[i].die = true;
}
}
int p1 = l, p2 = mid + , tot = l;
while(p1 <= mid && p2 <= r)
if(p[p1].b >= p[p2].b) tmp[tot++] = p[p1], p1++;
else tmp[tot++] = p[p2], p2++;
while(p1 <= mid) tmp[tot++] = p[p1], p1++;
while(p2 <= r) tmp[tot++] = p[p2], p2++;
for(int i = l; i <= r; i++) p[i] = tmp[i];
} int main() {
scanf("%d", &n);
for(int i = ; i <= n; i++) scanf("%d", &p[i].a);
for(int i = ; i <= n; i++) scanf("%d", &p[i].b);
for(int i = ; i <= n; i++) scanf("%d", &p[i].c);
int cnt = ;
sort(p + , p + + n, cmpa);
cdq(, n);
for(int i = ; i <= n; i++) if(p[i].die) cnt++;
printf("%d\n", cnt);
return ;
} /*
*/

Codeforces 12D Ball cdq分治的更多相关文章

  1. codeforces 12D Ball

    codeforces 12D Ball 这道题有两种做法 一种用树状数组/线段树维护区间最值,一种用map维护折线,昨天我刚遇见了一道类似的用STL维护折线的题目: 392D Three Arrays ...

  2. Codeforces 848C (cdq分治)

    Codeforces 848C Goodbye Souvenir Problem : 给一个长度为n的序列,有q个询问.一种询问是修改某个位置的数,另一种询问是询问一段区间,对于每一种值出现的最右端点 ...

  3. Codeforces 938G(cdq分治+可撤销并查集+线性基)

    题意: 有一个无向连通图,支持三个操作: 1 x y d : 新建一条x和y的无向边,长度为d 2 x y    :删除x和y之间的无向边 3 x y    :询问x到y的所有路径中(可以绕环)最短的 ...

  4. codeforces 762E(cdq分治)

    题意: n个电台,每个电台有三个属性xi, ri, fi.分别代表电台的坐标,电台的播报范围,以及播报的频率. 对于一对电台i, j,若min(ri, rj) >= |xi - xj|,那么他们 ...

  5. Codeforces 12D Ball(线段树)

    N ladies attend the ball in the King's palace. Every lady can be described with three values: beauty ...

  6. Codeforces 12D Ball 树形阵列模拟3排序元素

    主题链接:点击打开链接 #include<stdio.h> #include<iostream> #include<string.h> #include<se ...

  7. Codeforces 1045G AI robots [CDQ分治]

    洛谷 Codeforces 简单的CDQ分治题. 由于对话要求互相看见,无法简单地用树套树切掉,考虑CDQ分治. 按视野从大到小排序,这样只要右边能看见左边就可以保证互相看见. 发现\(K\)固定,那 ...

  8. Codeforces 1093E Intersection of Permutations [CDQ分治]

    洛谷 Codeforces 思路 一开始想到莫队+bitset,发现要T. 再想到分块+bitset,脑子一抽竟然直接开始写了,当然也T了. 最后发现这就是个裸的CDQ分治-- 发现\(a\)不变,可 ...

  9. Codeforces 848C Goodbye Souvenir [CDQ分治,二维数点]

    洛谷 Codeforces 这题我写了四种做法-- 思路 不管做法怎样,思路都是一样的. 好吧,其实不一样,有细微的差别. 第一种 考虑位置\(x\)对区间\([l,r]\)有\(\pm x\)的贡献 ...

随机推荐

  1. 洛谷SP16580 QTREE7 - Query on a tree VII(LCT,multiset)

    洛谷题目传送门 思路分析 维护子树最值还是第一次写QwQ 因为子树的最值会变化,所以不能简单地把最值记下来,还要维护一个平衡树,把每个子树的最大值扔进去,来资磁插入.删除和查询最值. 然后我就懒得手写 ...

  2. 【BZOJ1019】[SHOI2008]汉诺塔(数论,搜索)

    [BZOJ1019][SHOI2008]汉诺塔(数论,搜索) 题面 BZOJ 洛谷 题解 首先汉诺塔问题的递推式我们大力猜想一下一定会是形如\(f_i=kf_{i-1}+b\)的形式. 这个鬼玩意不好 ...

  3. pi的求法 acos(-1.0)

    pi=acos(-1.0) https://www.luogu.org/problemnew/show/T4529 #include <cstdio> #include <cstdl ...

  4. C/C++ exception类

    #include <iostream> #include <iomanip> #include <string> #include <sstream> ...

  5. linux basic ------ 多命令执行

    当我们需要一次执行多个命令的时候,命令之间需要用连接符连接,不同的连接符有不同的效果.下面我们总结一下,加以区分. (1)  ; 分号,没有任何逻辑关系的连接符.当多个命令用分号连接时,各命令之间的执 ...

  6. kubespray 一键安装k8s集群

    1. clone代码 git clone https://github.com/kubernetes-incubator/kubespray.git 2. 添加inventory/inventory ...

  7. python装饰器中@wraps作用--修复被装饰后的函数名等属性的改变

    Python装饰器(decorator)在实现的时候,被装饰后的函数其实已经是另外一个函数了(函数名等函数属性会发生改变),为了不影响,Python的functools包中提供了一个叫wraps的de ...

  8. 自己写的一个Vue

    下面这里是我自己写的一个小型的vue,原理就是proxy: //Proxy天生没有prototype,因此要加上,不然extends会报错 Proxy.prototype = Proxy.protot ...

  9. [iOS问题归总]iPhone上传项目遇到的问题

    1. 在上传项目的时候,UpLoad App Store后弹出iTunes Store operation failed. 错误原因:你在ItunesConnect(https://itunescon ...

  10. artTemplate

    1.http://www.cnblogs.com/jiqiyoudu/p/4588042.html