Problem Description

ZYBZYBZYB
has a premutation PPP,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)(i,j)(i < j)(i,j)(i<j)
is considered as a reverse log if Ai>AjA_i>A_jA​i​​>A​j​​
is matched.

Input

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

For each teatcase:

In the first line there is one number NNN.

In the next line there are NNN
numbers AiA_iA​i​​,describe
the number of the reverse logs of each prefix,

The input is correct.

1≤T≤51 \leq T \leq 51≤T≤5,1≤N≤500001
\leq N \leq 500001≤N≤50000

Output

For each testcase,print the ans.

Sample Input
1
3
0 1 2
Sample Output
3 1 2


问题描述
ZYBZYBZYB有一个排列PPP,但他只记得PPP中每个前缀区间的逆序对数,现在他要求你还原这个排列.

(i,j)(i<j)(i,j)(i < j)(i,j)(i<j)被称为一对逆序对当且仅当Ai>AjA_i>A_jA​i​​>A​j​​
输入描述
第一行一个整数TTT表示数据组数。

接下来每组数据:

第一行一个正整数NNN,描述排列的长度.

第二行NNN个正整数AiA_iA​i​​,描述前缀区间[1,i][1,i][1,i]的逆序对数.

数据保证合法.

1≤T≤51 \leq T \leq 51≤T≤5,1≤N≤500001 \leq N \leq 500001≤N≤50000
输出描述
TTT行每行NNN个整数表示答案的排列.
输入样例
1
3
0 1 2
输出样例
3 1 2

超时:::

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
int main ()
{
int T,n;
scanf("%d",&T);
long long int arr[50010];
int mark[50010],cnt;
int res[50010];
bool vis[50010];
for(int xx=0; xx<T; xx++)
{
memset(vis,0,sizeof(vis));
cnt = 0;
int n;
long long temp;
scanf("%d",&n);
if(n>=1)
scanf("%I64d",arr);
long long int xxx=0;
for(int i=1; i<n; i++){
scanf("%I64d",&temp);
arr[i] = temp-xxx,xxx=temp;
}
for(int i=0; i<n; i++)
{
for(int i=n-1; i>=0; i--)
{
if(arr[i]==0&&!vis[i])
{
mark[cnt++] = i;
arr[i]--;
vis[i]=1;
break;
}
else arr[i]--;
}
}
int mmax = n;
for(int i=0; i<n; i++,mmax--)
res[mark[i]] = mmax;
for(int i=0; i<n; i++){
if(i!=n-1) printf("%d ",res[i]);
else printf("%d",res[i]);
}
printf("\n");
}
return 0;
}

ZYB's Premutation POJ5592的更多相关文章

  1. ZYB's Premutation(有逆序数输出原序列,线段树)

    ZYB's Premutation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Othe ...

  2. BestCoder Round #65 (ZYB's Premutation)

    ZYB's Premutation Accepts: 220 Submissions: 983 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...

  3. hdu 5592 ZYB's Premutation (权值线段树)

    最近在线段树的世界里遨游,什么都能用线段树做,这不又一道权值线段树了么. ZYB's Premutation Time Limit: 2000/1000 MS (Java/Others)    Mem ...

  4. HDU 5592——ZYB's Premutation——————【线段树单点更新、单点查询】

    ZYB's Premutation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Othe ...

  5. [HDU5592] ZYB's Premutation

    [HDU5592] ZYB's Premutation 题目大意:一个由\([1,n]\)组成的数列,但不知道具体排列,但给出每个前缀的逆序对数目,让你还原排列 Solution 创造一颗\([1,n ...

  6. 线段树 - ZYB's Premutation

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

  7. Bestcoder round #65 && hdu 5592 ZYB's Premutation 线段树

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submissio ...

  8. HDU 5592 ZYB's Premutation

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5592 题意: http://bestcoder.hdu.edu.cn/contests/contes ...

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

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

随机推荐

  1. SAP Adapter启动报错

    在启动Adapter的时候,抛出GateWay Service Exception 当时用的gateway service是“sapgw00” 解决方法:这是由于当sap系统向本机注册服务的时候出错, ...

  2. wp8.1 Study15:后台任务

    一.介绍 1.多任务处理 什么是多任务处理?它意味着当App被挂起时,它仍然可以完成一些开发者设定的任务,比如更新tiles和toasts.预定toast和提醒.后台任务等. 2.后台任务 App可以 ...

  3. css浏览器窗口大小

    Window 尺寸 有三种方法能够确定浏览器窗口的尺寸(浏览器的视口,不包括工具栏和滚动条). 对于Internet Explorer.Chrome.Firefox.Opera 以及 Safari: ...

  4. C++二进制文件中读写bitset

    这个比较简单,直接上代码: bitset< > *b = >(); bitset< > *c = >(); ofstream out("I:\\test. ...

  5. C++ friend keyword

    You often need to split a class in half when the two halves will have different numbers of instances ...

  6. mysql-5.6.17-win32免安装版配置

    下载mysql-5.6.17-win32:官网下载地址百度   解压到自定义目录,我这里演示的是D:\wamp\mysql\   复制根目录下的my-default.ini,改名为my.ini,my. ...

  7. 关于ubuntu下词典安装

    圣诞快乐!merry xmas! 身为程序猿和研究僧,英文文献是经常接触的,所以在ubuntu下当然需要一款英汉词典啦 查了下推荐stardict的比较多,于是学着安装了下,感觉还不错,但是只有词典功 ...

  8. 更新EF,EF 报错

    在项目中,对一个视图进行了更新,增加了一个字段,然后需要更新EF访问,可是往往会报错, 查看映射关系发现EF将字段映射为主键,而视图没有进行ISNULL处理. 可以有两种处理方式: 1:修改视图对字段 ...

  9. xmind的第九天笔记

  10. thinkphp 内置标签volist 控制换行

    thinkphp 内置标签volist 控制换行 volist标签通常用于查询数据集(select方法)的结果输出,通常模型的select方法返回的结果是一个二维数组,可以直接使用volist标签进行 ...