PAT L2-014. 列车调度
2017-03-22 16:01
197 查看
贪心,树状数组,二分。
每次找一个比自己大一点点的值,树状数组上二分即可。
每次找一个比自己大一点点的值,树状数组上二分即可。
#include<map> #include<set> #include<ctime> #include<cmath> #include<queue> #include<string> #include<stack> #include<vector> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<functional> using namespace std; int n,a[100010],c[100010]; int lowbit(int x) { return x&(-x); } void update(int x,int v) { int p=x; while(p<=n) { c[p]=c[p]+v; p=p+lowbit(p); } } int get(int x) { int p=x,res=0; while(p) { res=res+c[p]; p=p-lowbit(p); } return res; } int main() { scanf("%d",&n); int ans=0; for(int i=1;i<=n;i++) { scanf("%d",&a[i]); int sum = get(n)-get(a[i]); if(sum==0) { update(a[i],1); ans++; continue; } int L=a[i], R=n, pos=-1; while(L<=R) { int mid = (L+R)/2; if(get(n)-get(mid-1)==sum) L = mid+1,pos=mid; else R = mid-1; } update(pos,-1); update(a[i],1); } printf("%d\n",ans); return 0; }
相关文章推荐
- 【PAT L2-014】列车调度(Dilworth定理)
- PAT - 天梯赛 L2-014 列车调度
- PAT L2-014. 列车调度 最长上升子序列
- L2-014. 列车调度Pat::集合
- PAT 天梯赛 L2-014. 列车调度 【队列】
- PAT L2-014. 列车调度 最长上升子序列
- PAT L2-014. 列车调度 最长上升子序列
- PAT(天梯赛练习题) -L2-014. 列车调度
- PAT:L2-014. 列车调度
- PAT L2-014. 列车调度 最长上升子序列
- L2-014. 列车调度-PAT团体程序设计天梯赛GPLT
- PAT L2-014. 列车调度 最长上升子序列
- PAT-L2-014. 列车调度
- PAT L2-014. 列车调度 最长上升子序列
- PAT L2-014. 列车调度 二分查找优化,递减序列
- PAT L2-014. 列车调度 最长上升子序列
- PAT L2-014. 列车调度 最长上升子序列
- PAT L2-014. 列车调度
- PAT L2-014 列车调度(Dilworth定理)
- PAT - 团体程序设计天梯赛-练习集 - L2-014 - 列车调度