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. [最近公共祖先] POJ 3728 The merchant

    The merchant Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 4556   Accepted: 1576 Desc ...

  2. 使用WinINet和WinHTTP实现Http访问

    使用WinINet和WinHTTP实现Http访问 Http访问有两种方式,GET和POST,就编程来说GET方式相对简单点,它不用向服务器提交数据,在这个例程中我使用POST方式,提交数据value ...

  3. erlang中的lists:foldl()的用法,格式转换实例应用

    lists:foldl(fun(),参数1,参数2):这个函数就是先把参数1传给fun()处理,然后将参数2(列表)中每一个元素,依次传给fun()函数进行处理. lists:foldl(fun(El ...

  4. JDBC成绩管理系统

    import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sq ...

  5. servlet执行流程

    视频地址:http://www.imooc.com/video/5550      1-6 用户输入地址:localhost:8080/MyFirstServletDemo/index.jsp (My ...

  6. CPU指令系统

    CPU就是通过指令系统来操控寄存器然后实现读取数据的,所以我们必须介绍一下CPU的指令系统 如果我们知道指令的英文全称,这对我们理解指令的作用有很大帮助,所以贴出指令英文全称 接下来就是介绍一些主要的 ...

  7. windows 版的julia repl 启动时间已经大大优化!

    julia 是一门语法类似python 偏向主要用于科学计算的语言,julia吸收了很多其它语言的优点,内置了大量函数,使用起来很方便. 之前windows下的 julia repl(交互解释器)启动 ...

  8. iOS UITableViewCell 中 调整imageView 的图片大小

    在我的项目中,很多地方都希望将UITableViewCell 中的imageView 能根据自己图片的大小来进行展示,而就为了解决这个问题又觉得重写UITableViewCell 很不值得. 如下: ...

  9. Ubuntu Command-Line: Enable Unlimited Scrolling in the Terminal

    At times when using the terminal, the output from a command can be so long, you simply can’t scroll ...

  10. bigworld源码分析(4)——BaseAppMgr分析

    BaseAppMgr是用来管理BaseApp的,在整个bigworld中只有一个.本篇就BaseAppMgr的一些核心功能进行分析: (1) BaseAppMgr是如何通知BaseApp创建Entit ...