传送门

N ladies attend the ball in the King's palace. Every lady can be described with three values: beauty, intellect and richness. King's Master of Ceremonies knows that ladies are very special creatures. If some lady understands that there is other lady at the ball which is more beautiful, smarter and more rich, she can jump out of the window. He knows values of all ladies and wants to find out how many probable self-murderers will be on the ball. Lets denote beauty of the i-th lady by Bi, her intellect by Ii and her richness by Ri. Then i-th lady is a probable self-murderer if there is some j-th lady that Bi < Bj, Ii < Ij, Ri < Rj. Find the number of probable self-murderers.

Input

The first line contains one integer N (1 ≤ N ≤ 500000). The second line contains Ninteger numbers Bi, separated by single spaces. The third and the fourth lines contain sequences Ii and Ri in the same format. It is guaranteed that 0 ≤ Bi, Ii, Ri ≤ 109.

Output

Output the answer to the problem.

Examples

Input
3
1 4 2
4 3 2
2 5 3
Output
1

题意:一个人的三个值都小于另一个人,这个人就会自杀,问有几个人自杀
题解:线段树降维,然而并不是很会
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<cmath>
#include<stack>
#include<cstdlib>
#include <vector>
#include <set>
#include<queue>
using namespace std; #define ll long long
#define llu unsigned long long
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
const int maxn = 5e5+;
const ll mod = 1e9+; int n;
struct node
{
int x,y,z;
}a[maxn]; int h[maxn]; struct Tree
{
int l,r,Max;
}segTree[maxn<<]; void push_up(int i)
{
segTree[i].Max = max(segTree[i<<].Max,segTree[(i<<)|].Max);
}
void build(int i,int l,int r)
{
segTree[i].l = l;
segTree[i].r = r;
segTree[i].Max = ;
if(l == r)
return;
int mid = (l + r)/;
build(i<<,l,mid);
build((i<<)|,mid+,r);
} int query(int i,int l,int r)
{
if(segTree[i].l == l && segTree[i].r == r)
return segTree[i].Max;
int mid = (segTree[i].l + segTree[i].r)/;
if(r < mid)
return query(i<<,l,r);
else if(l > mid)
return query((i<<)|,l,r);
else
return max(query(i<<,l,mid),query((i<<)|,mid+,r));
}
void update(int i,int k,int val)
{
if(segTree[i].l == k && segTree[i].r == k)
{
segTree[i].Max = max(segTree[i].Max,val);
return;
}
int mid = (segTree[i].l + segTree[i].r)/;
if(k <= mid)
update(i<<,k,val);
else
update((i<<)|,k,val);
push_up(i);
}
bool comp(node x,node y)
{
if(x.x != y.x)
return x.x > y.x;
else if(x.y != y.y)
return x.y > y.y;
else
return x.z > y.z;
}
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i].x);
for(int i=;i<=n;i++)
{
scanf("%d", &a[i].y);
h[i] = a[i].y;
}
for(int i=;i<=n;i++)
scanf("%d",&a[i].z);
sort(h+,h+n+);
int Size = unique(h+,h++n)-h-; //unique的作用是“去掉”容器中相邻元素的重复元素(不一定要求数组有序),所以如果想得到去重后的size,需要减去初始地址,lower_bound是得到地址
//cout<<Size<<endl;
build(,,Size+);
sort(a+,a++n,comp);
int preval = a[].x;
int prei,ans = ;
for(int i=;i<=n;)
{
prei = i;
for(;a[i].x == a[prei].x && i<=n;i++)
{
a[i].y = lower_bound(h+,h++Size,a[i].y)-h;
if(query(,a[i].y+,Size+)>a[i].z)
ans++;
}
for(;prei<i;prei++)
update(,a[prei].y,a[prei].z);
}
printf("%d\n",ans);
}

Ball CodeForces - 12D的更多相关文章

  1. Ball CodeForces - 12D (线段树)

    题目链接:https://cn.vjudge.net/problem/CodeForces-12D 题目大意:给你一个人的三个信息,如果存在一个人比当前人的这三个信息都大,那么这个人就会退出,问你最终 ...

  2. codeforces 12D Ball

    codeforces 12D Ball 这道题有两种做法 一种用树状数组/线段树维护区间最值,一种用map维护折线,昨天我刚遇见了一道类似的用STL维护折线的题目: 392D Three Arrays ...

  3. Codeforces 12D Ball(线段树)

    N ladies attend the ball in the King's palace. Every lady can be described with three values: beauty ...

  4. Codeforces 12D Ball 树形阵列模拟3排序元素

    主题链接:点击打开链接 #include<stdio.h> #include<iostream> #include<string.h> #include<se ...

  5. Codeforces 12D Ball cdq分治

    裸的cdq, 没啥好说的, 要注意mid左边和mid右边的a相同的情况. #include<bits/stdc++.h> #define LL long long #define fi f ...

  6. 线段树详解 (原理,实现与应用)(转载自:http://blog.csdn.net/zearot/article/details/48299459)

    原文地址:http://blog.csdn.net/zearot/article/details/48299459(如有侵权,请联系博主,立即删除.) 线段树详解    By 岩之痕 目录: 一:综述 ...

  7. Codeforces Gym 100015B Ball Painting 找规律

    Ball Painting 题目连接: http://codeforces.com/gym/100015/attachments Description There are 2N white ball ...

  8. Codeforces Beta Round #12 (Div 2 Only) D. Ball sort/map

    D. Ball Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/12/D D ...

  9. Codeforces Round #277.5 (Div. 2)-B. BerSU Ball

    http://codeforces.com/problemset/problem/489/B B. BerSU Ball time limit per test 1 second memory lim ...

随机推荐

  1. flash系统奔溃的主要原因

    1.内存泄露(内存超过系统允许的最大限制,11.4版本为2G) 2.脚本死循环 3.舞台内元件的大小超出了系统限制

  2. css3之图形绘制

    由于近期的项目中出现了不规则的边框和图形, 所以重新温习一下CSS3的图形绘制...样式绘制的图形比图片的性能要好,体验更佳,关键一点是更加有趣! 以下几个例子主要是运用了css3中border.bo ...

  3. php socket简单使用

    php的socket编程算是比较难以理解的东西吧,不过,我们只要理解socket几个函数之间的关系,以及它们所扮演的角色,那么理解起来应该不是很难了,在笔者看来,socket编程,其实就是建立一个网络 ...

  4. 【起航计划 025】2015 起航计划 Android APIDemo的魔鬼步伐 24 App->Notification->Notifying Service Controller service中使用Notification

    这个例子介绍了如何在Service中使用Notification,相关的类为NotifyingController和NotifyingService. 在Service中使用Notification的 ...

  5. SpringBoot常用应用程序属性

    参考地址: https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.h ...

  6. Linux 查看CPU、Memory等资源占用情况

    linux下获取占用CPU资源最多的10个进程,可以使用如下命令组合: ps aux|head -1;ps aux|grep -v PID|sort -rn -k +3|head linux下获取占用 ...

  7. CloudWAN

    类型: 定制服务 软件包: collaboration Enterprise integration integrated industry internet IT service/informati ...

  8. Python基础学习之标识符

    1.合法的Python标识符 Python标识符字符串规则和其他大部分用C编写的高级语言相似: 第一个字符必须是字母或下划线(_) 剩下的字符可以是字母和数字或下滑线 大小写敏感 标识符不能以数字开头 ...

  9. 史上最简单的SpringCloud教程 | 第十一篇: docker部署spring cloud项目

    转载请标明出处: 原文首发于:https://www.fangzhipeng.com/springcloud/2017/07/12/sc11-docker/ 本文出自方志朋的博客 一.docker简介 ...

  10. java 基础词汇 必须 第九天

    Collection 集合 List 列表集合 Set 不重复集合 Linked 链表 Vector 线程安全集合 Hash 哈希值 tree 树型结构 Map 键值对集合 add 增加 remove ...