Ball CodeForces - 12D
Posted smallhester
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ball CodeForces - 12D相关的知识,希望对你有一定的参考价值。
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
3
1 4 2
4 3 2
2 5 3
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+5; const ll mod = 1e9+7; int n; struct node { int x,y,z; }a[maxn]; int h[maxn]; struct Tree { int l,r,Max; }segTree[maxn<<2]; void push_up(int i) { segTree[i].Max = max(segTree[i<<1].Max,segTree[(i<<1)|1].Max); } void build(int i,int l,int r) { segTree[i].l = l; segTree[i].r = r; segTree[i].Max = 0; if(l == r) return; int mid = (l + r)/2; build(i<<1,l,mid); build((i<<1)|1,mid+1,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)/2; if(r < mid) return query(i<<1,l,r); else if(l > mid) return query((i<<1)|1,l,r); else return max(query(i<<1,l,mid),query((i<<1)|1,mid+1,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)/2; if(k <= mid) update(i<<1,k,val); else update((i<<1)|1,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=1;i<=n;i++) scanf("%d",&a[i].x); for(int i=1;i<=n;i++) { scanf("%d", &a[i].y); h[i] = a[i].y; } for(int i=1;i<=n;i++) scanf("%d",&a[i].z); sort(h+1,h+n+1); int Size = unique(h+1,h+1+n)-h-1; //unique的作用是“去掉”容器中相邻元素的重复元素(不一定要求数组有序),所以如果想得到去重后的size,需要减去初始地址,lower_bound是得到地址 //cout<<Size<<endl; build(1,1,Size+1); sort(a+1,a+1+n,comp); int preval = a[1].x; int prei,ans = 0; for(int i=1;i<=n;) { prei = i; for(;a[i].x == a[prei].x && i<=n;i++) { a[i].y = lower_bound(h+1,h+1+Size,a[i].y)-h; if(query(1,a[i].y+1,Size+1)>a[i].z) ans++; } for(;prei<i;prei++) update(1,a[prei].y,a[prei].z); } printf("%d ",ans); }
以上是关于Ball CodeForces - 12D的主要内容,如果未能解决你的问题,请参考以下文章
var ball0=new Ball("executing") 是怎样被执行的?
Codeforces Beta Round #12 (Div 2 Only) D. Ball 树状数组查询后缀最值
[Codeforces Round #522 (Div. 2, based on Technocup 2019 Elimination Round 3)][C. Playing Piano](代码片段