ZYB's Game

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5592

Description

ZYB has a premutation P,but he only remeber the reverse log of each prefix of the premutation,now he ask you to
restore the premutation.

Pair (i,j)(i<j) is considered as a reverse log if Ai>Aj is matched.

Input

In the first line there is the number of testcases T.

For each teatcase:

the first line there is one number N.

1≤T≤100000,1≤N≤10000000

Output

For each testcase,print the ans.

Sample Input

1
3
0 1 2

Sample Output

3 1 2

HINT

题意

题解:

很显然可以发现,a[i]-a[i-1],就表示在[1,i]中比i大的数有多少个

那么我们倒着做就好了,拿一个树状数组来维护就行了~

代码:

#include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std;
#define maxn 50005
long long a[maxn];
int ans[maxn];
#define lowbit(x) ((x)&(-x)) struct BinaryIndexTree
{
int val[maxn],sz; void init(int sz){
this->sz=sz;
memset(val , , sizeof(int)*(sz+));
} void updata(int pos ,int key){
while(pos<=sz){
val[pos]+=key;
pos+=lowbit(pos);
}
} long long prefixsum(int pos){
long long res=;
while(pos>){
res+=val[pos];
pos-=lowbit(pos);
}
return res;
} int query(int l,int r){
return prefixsum(r)-prefixsum(l-);
} //到第一个大于等于k的位置返回
//若不存在,返回-1
int lower_bound(long long k){
if(prefixsum(sz)<k) return -;
int l = , r = sz;
while(l <= r){
int mid = l + ((r-l)>>);
if(prefixsum(mid) < k) l = mid + ;
else r = mid - ;
}
return l;
} }solver; long long c[maxn];
int main()
{
int t;scanf("%d",&t);
for(int cas=;cas<=t;cas++)
{
memset(a,,sizeof(a));
memset(c,,sizeof(c));
int n;scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%I64d",&a[i]);
for(int i=;i<=n;i++)
c[i]=a[i]-a[i-];
solver.init(n);
for(int i=;i<=n;i++)
solver.updata(i,);
int tmp = ;
for(int i=n;i>=;i--)
{
ans[i]=solver.lower_bound(n-tmp-c[i]);
solver.updata(ans[i],-);
tmp++;
}
for(int i=;i<=n;i++)
{
if(i!=n)
printf("%d ",ans[i]);
else printf("%d\n",ans[i]);
}
}
}

hdu 5592 ZYB's Game 树状数组的更多相关文章

  1. HDU 5592 ZYB's Premutation(树状数组+二分)

    题意:给一个排列的每个前缀区间的逆序对数,让还原 原序列. 思路:考虑逆序对的意思,对于k = f[i] - f[i -1],就表示在第i个位置前面有k个比当前位置大的数,那么也就是:除了i后面的数字 ...

  2. HDU 5862 Counting Intersections(离散化+树状数组)

    HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 D ...

  3. hdu 5517 Triple(二维树状数组)

    Triple Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  4. HDU 1394 Minimum Inversion Number ( 树状数组求逆序数 )

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394 Minimum Inversion Number                         ...

  5. HDU 5862 Counting Intersections (树状数组)

    Counting Intersections 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 Description Given ...

  6. HDU 1394 Minimum Inversion Number (树状数组求逆序对)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394 题目让你求一个数组,这个数组可以不断把最前面的元素移到最后,让你求其中某个数组中的逆序对最小是多 ...

  7. HDU 5877 Weak Pair(树状数组)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5877 [题目大意] 给出一棵带权有根树,询问有几对存在祖先关系的点对满足权值相乘小于等于k. [题 ...

  8. HDU 2689 Sort it【树状数组】

    Sort it Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  9. HDU 5517---Triple(二维树状数组)

    题目链接 Problem Description Given the finite multi-set A of n pairs of integers, an another finite mult ...

随机推荐

  1. C++重要知识点小结---3

    C++重要知识点小结---1:http://www.cnblogs.com/heyonggang/p/3246631.html C++重要知识点小结---2:http://www.cnblogs.co ...

  2. LruCache--远程图片获取与本地缓存

    Class Overview A cache that holds strong references to a limited number of values. Each time a value ...

  3. Storage Keepers

    题意: n个仓库,m个人申请看管仓库,一个人可以看管多个仓库,一个仓库只能被一个人看管,每个人都有一个能力值,他看管的仓库的安全度U是能力值/看管仓库数,安全线L是U中的最小值,有多少能力公司发多少工 ...

  4. 安装配置Apache

    1.更新和升级系统 sudo apt-get update sudo apt-get upgrade 2.安装和配置apache 2.1.安装apache sudo apt-get install a ...

  5. 【LeetCode】226 - Invert Binary Tree

    Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9          to 4 / \ 7 2 / \ / \ 9 6 3 1   Notice: Goog ...

  6. [质疑]编程之美求N!的二进制最低位1的位置的问题

    引子:编程之美给出了求N!的二进制最低位1的位置的二种思路,但是呢?但是呢?不信你仔细听我道来. 1.编程之美一书给出的解决思路 问题的目标是N!的二进制表示中最低位1的位置.给定一个整数N,求N!二 ...

  7. python install 2.7.10

    CentOS 6.5升级Python和安装IPython 后来换成了CentOS 6.5,系统自带的Python版本是2.6.6. 图一:安装IPython需求 已经安装好gcc等编译工具.系统自带P ...

  8. 精选PSD素材下载周刊【Goodfav PSD 20130720】

    我们每周精选来自Goodfav PSD的免费PSD素材,有兴趣的朋友尤其是做设计工作的,不妨收藏或者下载. 这些现成的PSD素材能给我们一些相关的灵感,从而提高工作的效率. 1.File Upload ...

  9. QCon2013上海站总结 -- 前端开发

    选择这个专题开始主要有两个原因:一是这次会议关于前端开发的内容不多.二是我做过几年前端开发,这个专题对我来说会容易点:) 这次QCon上海关于前端开发有一个Keynote,一个Javascript专题 ...

  10. HW7.18

    public class Solution { public static void main(String[] args) { int[][] m = {{1, 2}, {3, 4}, {5, 6} ...