Codeforces 12D Ball cdq分治
裸的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分治的更多相关文章
- codeforces 12D Ball
codeforces 12D Ball 这道题有两种做法 一种用树状数组/线段树维护区间最值,一种用map维护折线,昨天我刚遇见了一道类似的用STL维护折线的题目: 392D Three Arrays ...
- Codeforces 848C (cdq分治)
Codeforces 848C Goodbye Souvenir Problem : 给一个长度为n的序列,有q个询问.一种询问是修改某个位置的数,另一种询问是询问一段区间,对于每一种值出现的最右端点 ...
- Codeforces 938G(cdq分治+可撤销并查集+线性基)
题意: 有一个无向连通图,支持三个操作: 1 x y d : 新建一条x和y的无向边,长度为d 2 x y :删除x和y之间的无向边 3 x y :询问x到y的所有路径中(可以绕环)最短的 ...
- codeforces 762E(cdq分治)
题意: n个电台,每个电台有三个属性xi, ri, fi.分别代表电台的坐标,电台的播报范围,以及播报的频率. 对于一对电台i, j,若min(ri, rj) >= |xi - xj|,那么他们 ...
- Codeforces 12D Ball(线段树)
N ladies attend the ball in the King's palace. Every lady can be described with three values: beauty ...
- Codeforces 12D Ball 树形阵列模拟3排序元素
主题链接:点击打开链接 #include<stdio.h> #include<iostream> #include<string.h> #include<se ...
- Codeforces 1045G AI robots [CDQ分治]
洛谷 Codeforces 简单的CDQ分治题. 由于对话要求互相看见,无法简单地用树套树切掉,考虑CDQ分治. 按视野从大到小排序,这样只要右边能看见左边就可以保证互相看见. 发现\(K\)固定,那 ...
- Codeforces 1093E Intersection of Permutations [CDQ分治]
洛谷 Codeforces 思路 一开始想到莫队+bitset,发现要T. 再想到分块+bitset,脑子一抽竟然直接开始写了,当然也T了. 最后发现这就是个裸的CDQ分治-- 发现\(a\)不变,可 ...
- Codeforces 848C Goodbye Souvenir [CDQ分治,二维数点]
洛谷 Codeforces 这题我写了四种做法-- 思路 不管做法怎样,思路都是一样的. 好吧,其实不一样,有细微的差别. 第一种 考虑位置\(x\)对区间\([l,r]\)有\(\pm x\)的贡献 ...
随机推荐
- Django入门项目实践(上)
项目结构 1.建立项目 File -->> New Project... 第一个Location是项目所在的目录,第二个Location是项目独立的Python运行环境,我们称之为Virt ...
- 解题:SDOI 2011 消耗战
题面 本身求答案是简单的树上DP,只需要求出根到每个点路径上的最小值,然后考虑割连父亲的边还是割所有儿子即可,但是每次都这样做一次显然不能通过,考虑优化 用虚树来优化:虚树是针对树上一些点建出来的一棵 ...
- 【洛谷P1991】无线通讯网
题目大意:给定一个 N 个顶点的完全图,边有边权,现在要求使得图中所有顶点联通的情况下,第 M-1 大的边最小值是多少. 题解:所有点联通的最小要求是所有点和连接这些点的边构成原图的一棵生成树,那么问 ...
- 关闭centos自动升级内核
八.关闭Centos自动更新chkconfig --list yum-updatesd #显示当前系统状态yum-updatesd 0:关闭 1:关闭 2:启用 3:启用 4:启用 ...
- python创建与遍历List二维列表
python创建与遍历List二维列表 觉得有用的话,欢迎一起讨论相互学习~Follow Me python 创建List二维列表 lists = [[] for i in range(3)] # 创 ...
- yearProgress.vue
<template> <div class="progressbar"> <el-progress :text-inside="true&q ...
- javascript沙箱模式
沙箱模式解决了命名空间模式的如下几个缺点: 1.对单个全局变量的依赖变成了应用程序的全局变量依赖.在命名空间模式中,是没有办法使同一个应用程序或库的2个版本运行在同一个页面中.2.对这种以点分割的名字 ...
- Linux中Nginx安装与配置详解
转载自:http://www.linuxidc.com/Linux/2016-08/134110.htm Linux中Nginx安装与配置详解(CentOS-6.5:nginx-1.5.0). 1 N ...
- Swagger文档化restful接口
1.注解 @Api:用在类上,说明该类的作用. @ApiOperation:注解来给API增加方法说明. @ApiImplicitParams : 用在方法上包含一组参数说明. @ApiImplici ...
- 第12月第29天 cocos quick manual
1. Example: $ cd cocos2d-x $ ./setup.py $ source FILE_TO_SAVE_SYSTEM_VARIABLE $ cocos new MyGame -p ...