HDU5592-ZYB's Premutation
来源:互联网 发布:淘宝怎么投诉卖家手机 编辑:程序博客网 时间:2024/06/06 01:37
ZYB's Premutation
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1085 Accepted Submission(s): 569
Problem Description
restore the premutation.
Pair
Input
In the first line there is the number of testcases T.
For each teatcase:
In the first line there is one numberN .
In the next line there areN numbers Ai ,describe the number of the reverse logs of each prefix,
The input is correct.
1≤T≤5 ,1≤N≤50000
For each teatcase:
In the first line there is one number
In the next line there are
The input is correct.
Output
For each testcase,print the ans.
Sample Input
130 1 2
Sample Output
3 1 2
Source
BestCoder Round #65
Recommend
hujie
题意:有一个序列,现在知道这个序列所有前缀的逆序对数,还原出这个序列
解题思路:a[i]-a[i-1]表示第i个数前面比它大的数字个数。用i-(a[i]-a[i-1])表示i个数中比第i个数小的个数,倒着跑,线段树维护每个区间还剩多少数字
#include <iostream> #include <cstdio> #include <string> #include <cstring> #include <cmath> #include <algorithm>#include <queue> #include <vector> #include <set> #include <stack> #include <map> #include <climits> using namespace std;#define LL long long const int INF = 0x3f3f3f3f;int t, n;int a[50009], sum[50009 << 2], ans[50009];void build(int k, int l, int r){sum[k] = r - l + 1;if (l == r) return;int mid = (l + r) >> 1;build(k << 1, l, mid), build(k << 1 | 1, mid + 1, r);}int query(int k, int l, int r, int p){sum[k]--;if (l == r) return l;int mid = (l + r) >> 1;if (sum[k << 1] >= p) return query(k << 1, l, mid, p);else return query(k << 1 | 1, mid + 1, r, p - sum[k << 1]);}int main(){scanf("%d", &t);while (t--){scanf("%d", &n);a[0] = 0;for (int i = 1; i <= n; i++) scanf("%d", &a[i]);build(1, 1, n);for (int i = n, j = 0; i >= 1; i--, j++){int p = a[i] - a[i - 1] + 1;p = n - j - p + 1;ans[n - j] = query(1, 1, n, p);}printf("%d", ans[1]);for (int i = 2; i <= n; i++) printf(" %d", ans[i]);printf("\n");}return 0;}
阅读全文
0 0
- hdu5592 ZYB's Premutation
- hdu5592-ZYB's Premutation
- HDU5592-ZYB's Premutation
- HDU5592 ZYB's Premutation(树状数组)
- HDU5592 ZYB's Premutation 树状数组应用
- ZYB's Premutation POJ5592
- BC65 ZYB's Premutation
- hdu 5529 ZYB's Premutation
- HDU 5592 ZYB's Premutation
- HDU 5592 ZYB's Premutation
- HDU 5592 ZYB's Premutation
- HDU 5592 ZYB's Premutation
- hdu 5592 ZYB's Premutation
- HDU 5592 ZYB's Premutation 线段树
- BestCoder #65 1003 ZYB's Premutation
- BestCoder Round #65 ZYB's Premutation
- hdu 5592 ZYB's Premutation (线段树)
- HDU 5592(ZYB's Premutation-线段树)
- nosql--简介
- 公务员考试在即,公务员礼仪具体需要注意哪些?
- spring技术内幕
- Jupyter 常用快捷键 及 常用方法笔记
- 52
- HDU5592-ZYB's Premutation
- 数据库三范式
- oj 给定一个字符串a, 将a中的大写字母 转换成小写,其它字符不变,并输出。
- 在物理机上安装centos7系统
- activiti工作流入门学习笔记
- 数据库基础
- jupyter使用
- qt安装方式总结
- nginx-负载均衡配置(入门)