bestcoder#65ZYB's Premutation 树状数组+二分
来源:互联网 发布:重庆中小企业的数据 编辑:程序博客网 时间:2024/06/09 14:39
#include<cstdio>#include<cstring>#include<iostream>using namespace std ;const int maxn = 50010 ;int tree[maxn] ;int n ;int getsum(int x){ int sum = 0 ; while(x){ sum += tree[x] ; x -= x&(-x) ; } return sum ;}void update(int x , int dx){ while(x <= n){ tree[x] += dx ; x += x&(-x) ; }}int find(int x , int ss){ int l = 1 ; int r = n ; while(l <= r){ int mid = (l + r) >> 1; int sum = ss-(mid-getsum(mid)) ; if(sum > x){ l=mid+1; } else if(sum <= x){ r=mid-1 ; } } return r+1 ;}int a[maxn] ;int ans[maxn] ;int main(){ int t ; scanf("%d" , &t) ; while(t--){ scanf("%d" , &n) ; for(int i = 1;i <= n;i++){ scanf("%d" , &a[i]) ; tree[i] = 0 ; } for(int i = n;i >= 1;i--){ int sum = a[i] - a[i-1] ; ans[i] = find(sum , i) ; update(ans[i] , 1) ; } for(int i = 1;i <= n;i++){ printf("%d%c" , ans[i] , i == n ?'\n':' ') ; } } return 0;}
0 1
- bestcoder#65ZYB's Premutation 树状数组+二分
- BestCoder Round #65 HDOJ5592 ZYB's Premutation(树状数组+二分)
- HDU 5592:ZYB's Premutation 树状数组+二分
- HDU 5592 ZYB's Premutation(二分+树状数组)
- HDU 5592 ZYB's Premutation(树状数组 + 二分)
- HDU5592 ZYB's Premutation(树状数组)
- HDU5592 ZYB's Premutation 树状数组应用
- BestCoder #65 1003 ZYB's Premutation
- BestCoder Round #65 ZYB's Premutation
- [hdu 5592 ZYB's Premutation] 树状数组+二分 求第K大数
- HDOJ 5592 ZYB's Premutation(逆序对变题:树状数组+二分||线段树)
- 【BestCoder Round 65C】【树状数组 动态查找第k大 O(nlogn)】ZYB's Premutation 告诉你前i个数中的逆序对数让你还原全排列
- BestCoder Round #65 C. ZYB's Premutation(线段树求第k大)
- BestCoder Round #65 HDU 5592 ZYB's Premutation (数据结构查询第K大)
- ZYB's Premutation POJ5592
- BC65 ZYB's Premutation
- hdu5592 ZYB's Premutation
- hdu5592-ZYB's Premutation
- 南大软院大神养成计划——第二十天
- 树莓派折腾之烧录系统、下载源代码、编译内核
- 文章标题
- 怎么删除github上的repository(仓库)
- JAVA——(3)常用类:Math、Scanner、String、StringBuffer、Array、Calendar、Date、Character、包装类(Intger)
- bestcoder#65ZYB's Premutation 树状数组+二分
- 对象的串行化(Serialization)
- Fragment
- Jaro-Winkler Distance JAVA代码实现版
- <c:choose>与<c:when>的一定要配合使用
- JavaScript、Ajax与jQuery的关系
- VI常用命令
- 【CUDA】第一个CUDA程序-addVector
- SpringMVC 通过XML方式进行配置解析BeanNameUrlHandlerMapping