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后面的数字 ...
随机推荐
- 什么是CPA, CPS, CPT?
在互联网上或移动端进行产品推广时,经常听到很多术语,什么CPA,CPS,CPT等等.不知是怎么来的,今天网上搜一下术语,在这里做一下笔记. CPA(Cost Per Action) 每行动成本. CP ...
- Linux学习 : 裸板调试 之 使用MMU
MMU(Memory Management Unit,内存管理单元),操作系统通过使用处理器的MMU功能实现以下:1)虚拟内存.有了虚拟内存,可以在处理器上运行比实际物理内存大的应用程序.为了使用虚拟 ...
- Python 初级项目:远程操控电脑(三)-极客学院
http://www.jikexueyuan.com/course/2376_1.html
- python leetcode 日记 --Contains Duplicate --217
题目 Given an array of integers, find if the array contains any duplicates. Your function should retur ...
- Linq学习总结1--参考Linq技术详解
2个要点: 1.linq操作的集合必须实现IEnumerable接口,所以在这3.0之前为实现该接口的集合需通过Cast或TypeOf方法转换成可Linq的集合; 2.查询式和Lame那啥表达式都可以 ...
- 黑马程序员——【Java基础】——网络编程
---------- android培训.java培训.期待与您交流! ---------- 一.网络模型概述 网络模型示意图: 说明: (1)数据的传输:在用户端,应用层的数据,经过层层封包,最后到 ...
- Python培训12期-day2作业-购物车
#!/usr/bin/env python import sys import os import getpass 商品={ '图书': { "<Puppet实战>": ...
- Recyclerview使用系列教材
Recylerview越来越多的人使用,本人录制了一套课程,欢迎大家观看,录制的比较仓促,第一课讲解的课程目录有点问题,请大家谅解,目录请看视频外该课程介绍的内容即可. 该课程付费课程包含: 1-Re ...
- 2016HUAS_ACM暑假集训2J - 今年暑假不AC
简单的贪心题.把节目的结束时间按升序排列,从第一个节目开始,寻找可以完全看完的节目. 这里用了结构体,所以要自己写排序方式. 总之,贪心的第一要义就是——排序! 本人新手,请体谅. #include& ...
- MSP430设置串口波特率的方法
给定一个BRCLK时钟源,波特率用来决定需要分频的因子N: N = fBRCLK/Baudrate 分频因子N通常是非整数值,因此至少一个分频器和一个调制阶段用来尽可能的接 ...