BestCoder Round #65 C. ZYB's Premutation(线段树求第k大)
来源:互联网 发布:网站连接数据库的函数 编辑:程序博客网 时间:2024/05/21 21:33
题意:
给定[1,i]前缀逆序对数,还原原始序列
分析:
先把前缀和还原成原来的,考虑倒着来,每个就相当于前面有多少个比自己大,线段树求第k大就好了,BIT什么的也可以
代码:
//// Created by TaoSama on 2015-12-05// Copyright (c) 2015 TaoSama. All rights reserved.////#pragma comment(linker, "/STACK:1024000000,1024000000")#include <algorithm>#include <cctype>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iomanip>#include <iostream>#include <map>#include <queue>#include <string>#include <set>#include <vector>using namespace std;#define pr(x) cout << #x << " = " << x << " "#define prln(x) cout << #x << " = " << x << endlconst int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;int n, a[N];int sum[N << 2], ans[N];void build(int l, int r, int rt) { sum[rt] = r - l + 1; if(l == r) return; int m = l + r >> 1; build(l, m, rt << 1); build(m + 1, r, rt << 1 | 1);}int query(int k, int l, int r, int rt) { --sum[rt]; if(l == r) return l; int m = l + r >> 1; if(k >= sum[rt << 1 | 1]) return query(k - sum[rt << 1 | 1], l, m, rt << 1); else return query(k, m + 1, r, rt << 1 | 1);}int main() {#ifdef LOCAL freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);// freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);#endif ios_base::sync_with_stdio(0); int t; scanf("%d", &t); while(t--) { scanf("%d", &n); for(int i = 1; i <= n; ++i) scanf("%d", a + i); build(1, n, 1); int all = n; for(int i = n; i; --i) { int k = a[i] - a[i - 1]; ans[i] = query(k, 1, n, 1); } for(int i = 1; i <= n; ++i) printf("%d%c", ans[i], " \n"[i == n]); } return 0;}
0 0
- BestCoder Round #65 C. ZYB's Premutation(线段树求第k大)
- BestCoder Round #65 HDU 5592 ZYB's Premutation (数据结构查询第K大)
- HDU.5592 ZYB's Premutation(线段树求第k大)
- HDU 5592ZYB's Premutation (线段树求第K大)
- BestCoder Round #65 ZYB's Premutation
- BestCoder Round #65 HDOJ5592 ZYB's Premutation(树状数组+二分)
- HDU 5592 ZYB's Premutation 线段树(查找动态区间第K大)
- HDU 5592 ZYB's Premutation 线段树(查找动态区间第K大)
- 【BestCoder Round 65C】【树状数组 动态查找第k大 O(nlogn)】ZYB's Premutation 告诉你前i个数中的逆序对数让你还原全排列
- BestCoder #65 1003 ZYB's Premutation
- 杭电 5592 ZYB's Premutation(线段树求第k大数)
- hdu 5592 ZYB's Premutation(线段树查询第k大的数)
- bestcoder#65ZYB's Premutation 树状数组+二分
- hdu 5592 ZYB's Premutation(线段树)
- BestCoder Round #65 B. ZYB's Game(组合游戏)
- BestCoder Round #65 D. ZYB's Tree(树形dp)
- BestCoder Round #65 ZYB's Biology
- BestCoder Round #65 ZYB's Game
- Activity的启动模式与flag详解
- Ubuntu有线网络不稳定掉线
- Cocos3.0学习笔记-Acition-基本动作
- Ubuntu和Widnows系统时差问题
- BestCoder Round #65 B. ZYB's Game(组合游戏)
- BestCoder Round #65 C. ZYB's Premutation(线段树求第k大)
- xutils 关于下载文件。
- BestCoder Round #65 D. ZYB's Tree(树形dp)
- 购物车页面去掉ecshop国家省市区客户手动填写收货地址的方法
- 搜狗2016 C++笔试题
- c++实现的任意进制数转十进制数算法
- 【转】unity跨平台文件操作详解
- thinkphp3.2 跨控制器调用
- AWS 假设 VPN (PPTP & L2TP) 整理