裸的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. 【转】Git 安装和使用教程

    git 提交 全部文件 git add .  git add xx命令可以将xx文件添加到暂存区,如果有很多改动可以通过 git add -A .来一次添加所有改变的文件.注意 -A 选项后面还有一个 ...

  2. 汉诺塔hanoi

    问题描述: 有一个梵塔,塔内有三个座A.B.C,A座上有诺干个盘子,盘子大小不等,大的在下,小的在上(如图). 把这些个盘子从A座移到C座,中间可以借用B座但每次只能允许移动一个盘子,并且在移动过程中 ...

  3. sking

    #include #include #include typedef struct SKI{ int data; int x; int y; char flag; int len; }STSKI; i ...

  4. Python微信红包算法

    sklearn实战-乳腺癌细胞数据挖掘(博主亲自录制视频) https://study.163.com/course/introduction.htm?courseId=1005269003& ...

  5. Golang的字符编码介绍

    Golang的字符编码介绍 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. Go里面内建仅支持UTF8字符串编码,因此如果你用fmt.Printf之类的函数无法将GBK,GB2312 ...

  6. 引用EChart和Bootstrap

    1.怎么引用Echart 下载之后,写一个html,里面这样写 <!DOCTYPE html> <html> <head> <meta charset=&qu ...

  7. .net MVC框架里怎么写控件

    .net的MVC框架如果选择了Razor引擎就需要自己来写控件了,这里列出了一些简单的控件的书写方法 @*这是TextBox控件的写法*@ @Html.TextBox("textbox1&q ...

  8. 说说SQL Server的数据类型

    以SQL Server为例,SQL Server的数据类型总共有33种,归纳为一下类别: 精确数字 Unicode字符串 近似数字 二进制字符串 日期和时间 其他数据类型 字符串   1.数字数据类型 ...

  9. oracle按照in的顺序进行排序

    oracle按照in的顺序进行排序 ,,) order by case id end;

  10. 网络技术之TCP三次握手

    在TCP/IP协议中,TCP协议提供可靠的连接服务,采用三次握手方式建立一个连接 第一次握手:c->s 建立连接时,客户端发送SYN包(syn=j){注:syn:Synchronize Sequ ...