HDU 5592 ZYB's Premutation
2015-12-11 17:42
429 查看
Problem Description
ZYBZYB has
a premutation PP,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) is
considered as a reverse log if A_i>A_jAi>Aj 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 NN.
In the next line there are NN numbers A_iAi,describe
the number of the reverse logs of each prefix,
The input is correct.
1
\leq T \leq 51≤T≤5,1
\leq N \leq 500001≤N≤50000
Output
For each testcase,print the ans.
Sample Input
Sample Output
3 1 2
根据逆序数求原序列,线段树优化一下
ZYBZYB has
a premutation PP,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) is
considered as a reverse log if A_i>A_jAi>Aj 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 NN.
In the next line there are NN numbers A_iAi,describe
the number of the reverse logs of each prefix,
The input is correct.
1
\leq T \leq 51≤T≤5,1
\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
根据逆序数求原序列,线段树优化一下
#include<cmath> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long LL; const int maxn = 1e5 + 5; int T, n, m, a[maxn], b[maxn], ans[maxn]; struct ST { int f[maxn * 5]; void build(int x,int l,int r) { if (l == r) f[x] = 1; else { int mid = l + r >> 1; build(x + x, l, mid); build(x + x + 1, mid + 1, r); f[x] = f[x + x] + f[x + x + 1]; } } int find(int x, int l, int r, int v) { if (l == r) { f[x]--; return l; } else { int mid = l + r >> 1; f[x]--; if (v > f[x + x + 1]) return find(x + x, l, mid, v - f[x + x + 1]); else return find(x + x + 1, mid + 1, r, v); } } }st; int main() { scanf("%d", &T); while (T--) { scanf("%d", &n); a[0] = 0; st.build(1, 1, n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); b[i] = a[i] - a[i - 1]; } for (int i = n; i; i--) { ans[i] = st.find(1, 1, n, b[i] + 1); } for (int i = 1; i <= n; i++) printf("%d%s", ans[i], i == n ? "\n" : " "); } return 0; }
相关文章推荐
- php array函数实例应用
- [留念贴] C#开发技术期末大作业——星月之痕
- 2-Eleventh Scrum Meeting20151211
- HDU 5591 ZYB's Game
- erlang四大behaviour之二-gen_fsm(转载)
- Qt:QML中,Warning: distance-field glyph is not available with index解决方法
- mysql 替换
- Linux中ping命令的用法
- Serializable 接口(序列化和反序列化)
- android 按键声音功能实现介绍
- iOS-SQLite3和FMDB使用
- 蓝桥杯——数列特征
- kernel logo到开机卡通片之间闪现黑屏(android 5.X)
- 解惑rJava R与Java的高速通道
- HDU 5590 ZYB's Biology
- Java中基于HTTP协议网络编程
- 使用单独创建的Xib
- SQL生成n位随机字符串
- 详解C# 迭代器
- 复习了一下NGUI