原题链接:http://codeforces.com/contest/12/problem/D
给一系列三维点(x,y,z)。求出满足以下条件的点个数: 对点 (x1,y1,z1 ) , 存在一个点 (x2,y2,z2) 使得 x2> x1, y2> y1, z2> z1。
先按 x 从大到小排序,再将 y 离散化。从前到向扫描,对于点(x,y,z), 在大于 y 的区间内找到最大的 z1,如果 z1> z, 则答案加 1.
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
int const N= 500100;
int tb[N<<2]= {0};
int n;
struct Node{
int x, y, z;
};
bool operator<( Node a, Node b ){
return a.x> b.x;
}
Node dat[N];
int num[N];
int query( int x, int y, int L, int R, int rt ){
if( x== L && y== R ) return tb[rt];
int mid= (L+ R)>>1;
if( y<= mid ) return query( x, y, L, mid, rt<<1 );
else if( x> mid ) return query( x, y, mid+ 1, R, rt<<1|1 );
else{
int a= query( x, mid, L, mid, rt<<1 );
int b= query( mid+ 1, y, mid+ 1, R, rt<<1|1 );
return max(a,b);
}
}
void update( int x, int d, int L, int R, int rt ){
if( L== R ){
tb[rt]= max( tb[rt], d );
return;
}
int mid= (L+ R)>>1;
if( x<= mid ) update( x, d, L, mid, rt<<1 );
else update( x, d, mid+ 1, R, rt<<1|1 );
tb[rt]= max( tb[rt<<1], tb[rt<<1|1] );
}
int main(){
scanf("%d", &n );
for( int i= 1; i<= n; ++i ) scanf("%d", &dat[i].x );
for( int i= 1; i<= n; ++i ){ scanf("%d", &dat[i].y ); num[i]= dat[i].y; }
for( int i= 1; i<= n; ++i ) scanf("%d", &dat[i].z );
sort( dat+ 1, dat+ 1+ n );
sort( num+ 1, num+ 1+ n );
int ans= 0, i, j, pre= 1;
for( i= 1; i<= n; i= j ){
for( j= i; j<= n && dat[j].x== dat[i].x; j++ ){
int pos= lower_bound( num+ 1, num+ 1+ n, dat[j].y )- num;
if( pos== n ) continue;
int Max= query( pos+ 1, n, 1, n, 1 );
if( Max> dat[j].z ) ans++;
}
for( j= i; j<= n && dat[j].x== dat[i].x; j++ ){
int pos= lower_bound( num+ 1, num+ 1+ n, dat[j].y )- num;
update( pos, dat[j].z, 1, n, 1 );
}
}
printf("%d\n", ans );
return 0;
}
分享到:
相关推荐
暴枚最长桌脚的长度$l$,然后长度比$l$长的桌脚全部都要砍掉长度比$l$短的桌脚选择代价前$k$小的砍掉用线段树维护;示例程序 :typedef long l
Codeforces 题库 101-200 共~500题 codeforces.com版权所有。 程序可提交至该网站评测。
这题如果没有输出2个解就很简单。 是个之前做过的类型: 把所有限制按R排序, 然后每次取出R最小的,然后从其L开始选,尽量选能选的中最小的。 这样选如果能选完,就说明有解。 贪心正确性显然:R大的至少可以选则R...
codeforces编程网站预测分数插件
Codeforces 题库 001-100 共~500题 codeforces.com版权所有。 程序可提交至该网站评测。
使用于Google Chrome的Codeforces Enhancer 1.1.2插件安装包。 版本:codeforces enhancer 1.1.2 使用浏览器:Google Chrome
Codeforces 185A - Plant 全测试点49个
codeforces 19 E Fairy 一道比较难的题目的解题报告 推荐阅读
Codeforces global round 10 codes
Codeforces round 678 division 2 codes
Some of the Codeforces problems codes
Codeforces round 678 D2_Codeforces_源码
一个Codeforces、牛客竞赛、AtCoder平台的编程竞赛查询插件,ACMer必备.zip
打codeforces的神器
lucifer1004大佬的博客cf上分攻略故里大佬的githubcf思维题刷题数:44- (1421)codeforces 676 div2 A,B done
codeforces-js Codeforces JS
Codeforces Round #723 (Div. 2).md
使用 C# + WPF 开发 --- 还在发愁打了那么多场比赛都没有进入首页么? 还在为了前 5 的 hacker 名额阅读千份代码么? 是的,你没有看错! 这是一个 Edu & Div.3 轮 Open hacking 错误代码自动查找器!...
PDF-CodeForces问题 PDF文件中的CodeForces问题 利用CodeForces提取在这个库中的文件 ,文件夹名代表来自CodeForces网址contests`的ID,每个文件夹包含比赛的问题。 有关CodeForces竞赛的疯狂事实 CodeForces上有937...
Codeforces 题库 201-294 共~500题 codeforces.com版权所有。 程序可提交至该网站评测。