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 树状数组降维的更多相关文章

  1. hdu1541树状数组(降维打击)

    题目链接:http://icpc.njust.edu.cn/Problem/Hdu/1541/ 题意是:在二维图上有一系列坐标,其中坐标给出的顺序是:按照y升序排序,如果y值相同则按照x升序排序.这个 ...

  2. bzoj 3295 动态逆序对 (三维偏序,CDQ+树状数组)

    链接:https://www.lydsy.com/JudgeOnline/problem.php?id=3295 思路: 可以将这道题看成倒着插入,这样就可以转化成求逆序对数,用CDQ分治降维,正反用 ...

  3. HDU 4247 Pinball Game 3D(cdq 分治+树状数组+动态规划)

    Pinball Game 3D Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  4. 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 ...

  5. BZOJ 1103: [POI2007]大都市meg [DFS序 树状数组]

    1103: [POI2007]大都市meg Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2221  Solved: 1179[Submit][Sta ...

  6. bzoj1878--离线+树状数组

    这题在线做很麻烦,所以我们选择离线. 首先预处理出数组next[i]表示i这个位置的颜色下一次出现的位置. 然后对与每种颜色第一次出现的位置x,将a[x]++. 将每个询问按左端点排序,再从左往右扫, ...

  7. codeforces 597C C. Subsequences(dp+树状数组)

    题目链接: C. Subsequences time limit per test 1 second memory limit per test 256 megabytes input standar ...

  8. BZOJ 2434: [Noi2011]阿狸的打字机 [AC自动机 Fail树 树状数组 DFS序]

    2434: [Noi2011]阿狸的打字机 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 2545  Solved: 1419[Submit][Sta ...

  9. BZOJ 3529: [Sdoi2014]数表 [莫比乌斯反演 树状数组]

    3529: [Sdoi2014]数表 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 1399  Solved: 694[Submit][Status] ...

随机推荐

  1. CUDA开发

    CUB库 https://nvlabs.github.io/cub/index.html

  2. Nginx 磁盘IO的优化

    L:132

  3. sws_getContext函数参数介绍

    原型: SwsContext *sws_getContext(int srcW, int srcH, enum AVPixelFormat srcFormat, int dstW, int dstH, ...

  4. python 模块之-shelve

    shelve模块比pickle模块简单,只有一个open函数,返回类似字典的对象,可读可写;key必须为字符串,而值可以是python所支持的数据类型 import shelve f = shelve ...

  5. linux系统版本大全

    Linux系统下载地址:http://www.jb51.net/LINUXjishu/239493.html linux系统教学视频:http://www.uplinux.com/shipin/lin ...

  6. 数据库SQL SELECT查询的工作原理

    一般开发员只会应用SQL的四条经典语句:select,insert,delete,update.但是我从来没有研究过它们的工作原理,这篇我想说一说select在数据库中的工作原理. B/S架构中最经典 ...

  7. A - 敌兵布阵 HDU - 1166 线段树(多点修改当单点修改)

    线段树板子题练手用 #include<cstdio> using namespace std; ; int a[maxn],n; struct Node{ int l,r; long lo ...

  8. Destroying the bus stations HDU - 2485(最小割点)

    题意: 就是求最小割点 解析: 正向一遍spfa 反向一遍spfa  然后遍历每一条边,对于当前边 如果dis1[u] + dis2[v] + 1 <= k 那么就把这条边加入到网络流图中, 每 ...

  9. 【XSY2744】信仰圣光 分治FFT 多项式exp 容斥原理

    题目描述 有一个\(n\)个元素的置换,你要选择\(k\)个元素,问有多少种方案满足:对于每个轮换,你都选择了其中的一个元素. 对\(998244353\)取模. \(k\leq n\leq 1525 ...

  10. BZOJ1095 [ZJOI2007] Hide 捉迷藏 (括号序列 + 线段树)

    题意 给你一颗有 \(n\) 个点的树 , 共有 \(m\) 次操作 有两种类别qwq 将树上一个点染黑/白; 询问树上最远的两个黑点的距离. \((n \le 200000, m ≤500000)\ ...