ZYB's Premutation POJ5592
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_jAi>Aj
is matched.
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_iAi,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
For each testcase,print the ans.
1
3
0 1 2
3 1 2
问题描述
ZYBZYBZYB有一个排列PPP,但他只记得PPP中每个前缀区间的逆序对数,现在他要求你还原这个排列. (i,j)(i<j)(i,j)(i < j)(i,j)(i<j)被称为一对逆序对当且仅当Ai>AjA_i>A_jAi>Aj
第一行一个整数TTT表示数据组数。 接下来每组数据: 第一行一个正整数NNN,描述排列的长度. 第二行NNN个正整数AiA_iAi,描述前缀区间[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的更多相关文章
- ZYB's Premutation(有逆序数输出原序列,线段树)
ZYB's Premutation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
- BestCoder Round #65 (ZYB's Premutation)
ZYB's Premutation Accepts: 220 Submissions: 983 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
- hdu 5592 ZYB's Premutation (权值线段树)
最近在线段树的世界里遨游,什么都能用线段树做,这不又一道权值线段树了么. ZYB's Premutation Time Limit: 2000/1000 MS (Java/Others) Mem ...
- HDU 5592——ZYB's Premutation——————【线段树单点更新、单点查询】
ZYB's Premutation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Othe ...
- [HDU5592] ZYB's Premutation
[HDU5592] ZYB's Premutation 题目大意:一个由\([1,n]\)组成的数列,但不知道具体排列,但给出每个前缀的逆序对数目,让你还原排列 Solution 创造一颗\([1,n ...
- 线段树 - ZYB's Premutation
ZYB has a premutation P,but he only remeber the reverse log of each prefix of the premutation,now he ...
- Bestcoder round #65 && hdu 5592 ZYB's Premutation 线段树
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submissio ...
- HDU 5592 ZYB's Premutation
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5592 题意: http://bestcoder.hdu.edu.cn/contests/contes ...
- HDU 5592 ZYB's Premutation(树状数组+二分)
题意:给一个排列的每个前缀区间的逆序对数,让还原 原序列. 思路:考虑逆序对的意思,对于k = f[i] - f[i -1],就表示在第i个位置前面有k个比当前位置大的数,那么也就是:除了i后面的数字 ...
随机推荐
- shell使用随笔
001 对文件某一列求和 awk '{sum += $collum};END {print sum}' /path/to/your/file 2 3 3 5 假设文件内容如上所示: # awk '{s ...
- Maven+SSM搭建总结(非教程)
记录我用Maven搭建Spring+SpringMVC+Mybatis项目的过程. 网上关于这个的详细教程有很多,但是优质而适合自己看的需要自己筛选以下我看过的几篇认为讲的比较详细的资源(照着做吧,做 ...
- 使用squid配置透明代理并对上网行为进行控制
使用Squid配置透明代理 环境:CentOS 6.4 + squid-3.1.10-20.el6_5.3.x86_64 1.检查squid是否默认安装,没有安装先安装 rpm -qa squid 假 ...
- 简单使用SQLite 的增删改查
1.插入 第一种方式 INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) VALUES (1, 'Paul', 32, 'California', 200 ...
- 安卓手机上的python运行环境-qpython
qpython是一个能让安卓手机运行和编写python的APP,到网上下载APK安装或者在GOOGLE PLAY搜索安装即可. 安装之后你可以你手机跑自己的python程序. qpython有两个大版 ...
- 转 Flex MXML编译成AS类
2009-09-22 23:25 Flex MXML编译成AS类 由“Flex 基础”文中可知:每一个mxml文件首先要编译成as文件,然后再译成swf文件.app.mxml文件编译后会产生一系列中间 ...
- 详解Android功耗分析工具Power Tutor的使用
简介: PowerTutor 是由美国密歇根大学在谷歌的指导下开发的.它是用来展示google智能手机中主要组件或应用功耗的一种应用程序.例如,CPU,网络链接,LCD显示屏,GPS等.它允许开发者很 ...
- webApp--cordova 系列1
1.在node,npm 可用的前提下 npm install -g cordova 大约10分钟后装完,cmd中输入cordova -v 验证是否安装成功 2.cordova项目打包是用ant完成, ...
- 实时刷新Winform中Label的Text
最直白的例子: private void btnStart_Click(object sender, EventArgs e) { ; ) { labelTime.Text = i.ToString( ...
- 从零开始学习Node.js例子四 多页面实现数学运算
app-node.js ; var http = require('http'); var htutil = require('./htutil'); var server = http.create ...