Codeforces 12D Ball 树状数组模拟3个元素的排序
2014-06-27 00:08
363 查看
题目链接:点击打开链接
#include<stdio.h> #include<iostream> #include<string.h> #include<set> #include<vector> #include<map> #include<math.h> #include<queue> #include<string> #include<stdlib.h> #include<algorithm> using namespace std; #define N 500005 #define ll int ll n; ll c , maxn; inline ll lowbit(ll x){return x&(-x);} void change(ll pos, ll val){ while(pos)c[pos]=max(c[pos],val), pos-=lowbit(pos); } ll maxx(ll pos){ ll ans = -1; while(pos<=maxn)ans = max(ans,c[pos]),pos+=lowbit(pos); return ans; } struct node{ ll b[3],num; }w ; bool cmp0(node x, node y){return x.b[0]<y.b[0];} bool cmp1(node x, node y){return x.b[1]>y.b[1];} int main(){ ll i,j; while(cin>>n) { for(i=0;i<n;i++)scanf("%d",&w[i].b[0]); for(i=0;i<n;i++)scanf("%d",&w[i].b[1]); for(i=0;i<n;i++)scanf("%d",&w[i].b[2]); sort(w, w+n, cmp0); ll rank = 1; w[0].num = 1; for(i=1;i<n;i++) { if(w[i].b[0]==w[i-1].b[0])w[i].num = rank; else w[i].num = ++rank; } sort(w,w+n,cmp1); for(i=1;i<=rank;i++)c[i]=-1; maxn = rank; i = 0; ll ans = 0; while(i<n) { for(j = i; j < n && w[i].b[1] == w[j].b[1]; j++) if(maxx(w[j].num+1)>w[j].b[2]) ans++; for(j = i; j < n && w[i].b[1] == w[j].b[1]; j++) change(w[j].num, w[j].b[2]); i = j; } cout<<ans<<endl; } return 0; }
相关文章推荐
- 树状数组模拟3个元素的排序 Codeforces 12D Ball
- Codeforces 12D Ball 树形阵列模拟3排序元素
- CodeForces 12D Ball 多级排序 + 离散 + 线段树
- Java学习之数组1(1.数组的声明;2.元素为引用数据类型的数组;3.关于main方法里的String[] args;4.数组排序;5.数3退1 数组算法,(用数组模拟链表);6数组查找之二分法;7数组的拷贝)
- Codeforces 101B Buses 排序+树状数组
- CodeForces 545D Queue (排序模拟)
- CF-12D - Ball(排序+MAP)
- Codeforces - 609C.Load Balancing 排序、模拟
- CF-12D - Ball(排序+MAP)
- codeforces 845D Driving Test (模拟+思维)
- 模拟元素点击的几种方式
- 已有一个已排好的9个元素的数组,今输入一个数要求按原来排序的规律将它插入数组中
- 面试小结:对List集合中的元素进行排序
- JavaScript事件模拟元素拖动
- [ActionScript 3.0] 对数组中的元素进行排序Array.sort()的方法
- codeforces 479B. Towers C - Exams【排序】
- Android学习之使用Comparable或Comparator比较和排序元素
- 排序网络(C#模拟)
- CodeForces 1208 B. Physics Practical 区间统计,树状数组
- Codeforces 755-D. PolandBall and Polygon(树状数组+计算几何)