CodeForces12D 树状数组降维
http://codeforces.com/problemset/problem/12/D
题意
给N (N<=500000)个点,每个点有x,y,z ( 0<= x,y,z <=10^9 )
对于某点(x,y,z),若存在一点(x1,y1,z1)使得x1 > x && y1 > y && z1 > z 则点(x,y,z)是特殊点。
问N个点中,有多少个特殊点。
乍一看以为是裸的三位偏序问题,直接联想到了cdq分治,但是事实上这题和三位偏序有很大的差异,三位偏序问题求的是偏序的组数,但这题问的是完全被小于的个数,cdq分治上很难维护一个点是否已经被“超越”过,也不需要这么麻烦的去维护,事实上一维将x从大到小排序,一维作为树状数组上点的位置,越大的位置在越靠前,一维就是树状数组维护的前缀最大值即可。
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
const double eps = 1e-;
const int maxn = 5e5 + ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,tmp,K,cnt;
int Hash[maxn];
struct Node{
int a,b,c;
}node[maxn];
bool cmp(Node a,Node b){
return a.a > b.a;
}
int tree[maxn];
void add(int x,int y){
for(;x <= cnt;x += x & -x) tree[x] = max(tree[x],y);
}
int getmax(int x){
int s = ;
for(;x > ;x -= x & -x) s = max(s,tree[x]);
return s;
}
int main()
{
Sca(N);
For(i,,N) scanf("%d",&node[i].a);
For(i,,N) scanf("%d",&node[i].b);
For(i,,N) scanf("%d",&node[i].c);
For(i,,N) Hash[i] = node[i].c;
sort(Hash + ,Hash + + N);
cnt = unique(Hash + ,Hash + + N) - Hash - ;
For(i,,N) node[i].c = cnt + - (lower_bound(Hash + ,Hash + + cnt,node[i].c) - Hash);
sort(node + ,node + + N,cmp);
int ans = ;
For(i,,N){
int j = i;
while(j <= N && node[i].a == node[j].a) j++;j--;
For(k,i,j){
int t = getmax(node[k].c - );
if(t > node[k].b) ans++;
}
For(k,i,j) add(node[k].c,node[k].b);
i = j;
}
Pri(ans);
#ifdef VSCode
system("pause");
#endif
return ;
}
CodeForces12D 树状数组降维的更多相关文章
- hdu1541树状数组(降维打击)
题目链接:http://icpc.njust.edu.cn/Problem/Hdu/1541/ 题意是:在二维图上有一系列坐标,其中坐标给出的顺序是:按照y升序排序,如果y值相同则按照x升序排序.这个 ...
- bzoj 3295 动态逆序对 (三维偏序,CDQ+树状数组)
链接:https://www.lydsy.com/JudgeOnline/problem.php?id=3295 思路: 可以将这道题看成倒着插入,这样就可以转化成求逆序对数,用CDQ分治降维,正反用 ...
- HDU 4247 Pinball Game 3D(cdq 分治+树状数组+动态规划)
Pinball Game 3D Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 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 ...
- BZOJ 1103: [POI2007]大都市meg [DFS序 树状数组]
1103: [POI2007]大都市meg Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2221 Solved: 1179[Submit][Sta ...
- bzoj1878--离线+树状数组
这题在线做很麻烦,所以我们选择离线. 首先预处理出数组next[i]表示i这个位置的颜色下一次出现的位置. 然后对与每种颜色第一次出现的位置x,将a[x]++. 将每个询问按左端点排序,再从左往右扫, ...
- codeforces 597C C. Subsequences(dp+树状数组)
题目链接: C. Subsequences time limit per test 1 second memory limit per test 256 megabytes input standar ...
- BZOJ 2434: [Noi2011]阿狸的打字机 [AC自动机 Fail树 树状数组 DFS序]
2434: [Noi2011]阿狸的打字机 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 2545 Solved: 1419[Submit][Sta ...
- BZOJ 3529: [Sdoi2014]数表 [莫比乌斯反演 树状数组]
3529: [Sdoi2014]数表 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 1399 Solved: 694[Submit][Status] ...
随机推荐
- Spring MVC 使用介绍(一)—— 概述
一.Web MVC简介 1.经典的MVC架构 存在的问题:1.控制器负责流程控制.请求数据整理与校验.模型与视图选择等功能,过于复杂.2.模型层没有进行分层设计 2.改进的MVC设计 1)控制器功能拆 ...
- Spring MVC启动过程(1):ContextLoaderListener初始化
此文来自https://my.oschina.net/pkpk1234/blog/61971 (写的特别好)故引来借鉴 Spring MVC启动过程 以Tomcat为例,想在Web容器中使用Spirn ...
- Sum of Consecutive Prime Numbers POJ - 2739 线性欧拉筛(线性欧拉筛证明)
题意:给一个数 可以写出多少种 连续素数的合 思路:直接线性筛 筛素数 暴力找就行 (素数到n/2就可以停下了,优化一个常数) 其中:线性筛的证明参考:https://blog.csdn.net ...
- 实验九 在JSP中使用数据库
实验性质:验证性 实验学时: 1学时 实验地点: 一 .实验目的与要求 1. 掌握在JSP中使用数据库的方法. 2. 掌握JSP对数据库的基本操作:增.删.改.查. 二. 实验内容 1.JSP访问数据 ...
- python3,打印一年的某一天是一年的第几天
year = int(input('year:')) month = int(input('month:')) day = int(input('day:')) months = (0,31,59,9 ...
- 基于 __new__ 方法的单例模式
单例模式定义 首次实例化创建实例化对象 之后的每次实例化都用最初的实例化对象 即单实例模式 __new__ 的原理 __new__ 方法可以在 __init__ 方法执行 这样可以在初始化之前进行一系 ...
- MT【274】一道漂亮的不等式题
已知$x_1^2+x_2^2+\cdots+x_6^2=6,x_1+x_2+\cdots+x_6=0,$证明:$x_1x_2\cdots x_6\le\dfrac{1}{2}$ 解答:显然只需考虑2个 ...
- MT【271】一道三角最值问题
若不等式$k\sin^2B+\sin A\sin C>19\sin B\sin C$对任意$\Delta ABC$都成立,则$k$的最小值为_____ 分析:由正弦定理得$k>\dfrac ...
- zabbix3.4.6之自动发现与自动注册
在zabbix中添加新主机时,是需要手动添加,但在zabbix的Action里有两项功能,自动发现与自动注册,运用这两个功能中任意一个都可以实现自动添加机器,但添加的主机名是IP地址. 自动发现:添加 ...
- 【转】C++ const 关键字总结
const是一个C++语言的限定符,它限定一个变量不允许被改变.使用const在一定程度上可以提高程序的安全性和可靠性.另外,在观看别人代码的时候,清晰理解const所起的作用,对理解对方的程序也有一 ...