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\)的贡献 ...
随机推荐
- 学习4__STM32--中断
Cortex-M处理器的NVIC接收中断请求各种源 > 从图中可看出,NVIC是一个外设中断的管理器,简化core的工作,控制着整个芯片的中断功能 > NVIC负责给外设中断分配优先级,使 ...
- POJ 3436 ACM Computer Factory (网络流,最大流)
POJ 3436 ACM Computer Factory (网络流,最大流) Description As you know, all the computers used for ACM cont ...
- npm 设置地址
-- 查看当前地址: npm config get registry https://registry.npmjs.org/ npm config get disturl undefined -- 设 ...
- 【转】如何学习android开发
1.Java基础 很多朋友一上手就开始学习Android,似乎太着急了一些.Android应用程序开发是以Java语言为基础的,所以没有扎实的Java基础知识,只 是机械的照抄别人的代码,是没有任何意 ...
- gdb调试遇到的问题
解决方法:http://stackoverflow.com/questions/31062010/ubuntu-14-04-gcc-4-8-4-gdb-pretty-printing-doesnt-w ...
- What does -1 mean in numpy reshape?
The criterion to satisfy for providing the new shape is that 'The new shape should be compatible wit ...
- Go_21: Golang 中 time 包的使用二
常量声明: const TimeLayout = "2006-01-02 15:04:05" 这是个奇葩,必须是这个时间点,据说是 go 诞生之日, 记忆方法:6-1-2-3-4- ...
- np.linespace使用方法
np.linespace用法 觉得有用的话,欢迎一起讨论相互学习~Follow Me 生成指定范围内指定个数的一维数组 def linspace(start, stop, num=50, endpoi ...
- 数据结构(三)串---KMP模式匹配算法实现及优化
KMP算法实现 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include ...
- Gnucash数据库结构