hdu 5592 ZYB's Premutation (权值线段树)
最近在线段树的世界里遨游,什么都能用线段树做,这不又一道权值线段树了么。
ZYB's Premutation
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1029 Accepted Submission(s): 528
has a premutation P
,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)
is considered as a reverse log if Ai
>A
j
is matched.
For each teatcase:
In the first line there is one number N
.
In the next line there are N
numbers Ai
,describe the number of the reverse logs of each prefix,
The input is correct.
1≤T≤5
,1≤N≤50000
3
0 1 2
#include<cstdio>
#include<iostream>
#include<cstring>
#define clr(x) memset(x,0,sizeof(x))
using namespace std;
struct segtree
{
int l,r,val,num;
}tree[];
int n,m,rev[],ans[];
void init(int i,int l,int r);
int query(int i,int k);
void update(int i,int pos);
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
clr(rev);
clr(ans);
for(int i=;i<=n;i++)
scanf("%d",&rev[i]);
init(,,n);
for(int i=n;i>=;i--)
{
ans[i]=query(,i-(rev[i]-rev[i-]));
update(,ans[i]);
}
for(int i=;i<n;i++)
printf("%d ",ans[i]);
printf("%d\n",ans[n]);
}
return ;
}
void init(int i,int l,int r)
{
tree[i].l=l;
tree[i].r=r;
tree[i].num=r-l+;
tree[i].val=r;
if(l==r)
return;
int mid=(l+r)>>;
init(i<<,l,mid);
init((i<<)|,mid+,r);
}
int query(int i,int k)
{
if(tree[i].l==tree[i].r)
return tree[i].val;
if(tree[i<<].num>=k)
return query(i<<,k);
else
return query((i<<)|,k-tree[i<<].num);
}
void update(int i,int pos)
{
tree[i].num--;
if(tree[i].l==tree[i].r)
return ;
if(pos<=tree[i<<].r)
update(i<<,pos);
else
update((i<<)|,pos);
return ;
}
hdu 5592 ZYB's Premutation (权值线段树)的更多相关文章
- HDU - 5592 ZYB's Premutation (权值线段树)
题意:给出序列前k项中的逆序对数,构造出这个序列. 分析:使用权值线段树来确定序列元素. 逆序对的数量肯定是递增的,从最后一个元素开始逆向统计,则\(a[i] - a[i-1]\)即位置i之前比位置i ...
- HDU 5249:KPI(权值线段树)
KPI Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Desc ...
- Hdu P1394 Minimum Inversion Number | 权值线段树
题目链接 题目翻译: 约定数字序列a1,a2,...,an的反转数是满足i<j和ai>aj的数对(ai,aj)的数量. 对于给定的数字序列a1,a2,...,an,如果我们将第1到m个数字 ...
- HDU 6464 免费送气球 【权值线段树】(广东工业大学第十四届程序设计竞赛)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6464 免费送气球 Time Limit: 2000/1000 MS (Java/Others) M ...
- HDU 6464 权值线段树 && HDU 6468 思维题
免费送气球 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- 2019年CCPC网络赛 HDU 6703 array【权值线段树】
题目大意:给出一个n个元素的数组A,A中所有元素都是不重复的[1,n].有两种操作:1.将pos位置的元素+1e72.查询不属于[1,r]中的最小的>=k的值.强制在线. 题解因为数组中的值唯一 ...
- R - Weak Pair HDU - 5877 离散化+权值线段树+dfs序 区间种类数
R - Weak Pair HDU - 5877 离散化+权值线段树 这个题目的初步想法,首先用dfs序建一颗树,然后判断对于每一个节点进行遍历,判断他的子节点和他相乘是不是小于等于k, 这么暴力的算 ...
- HDU - 2665 Kth number 主席树/可持久化权值线段树
题意 给一个数列,一些询问,问$[l,r]$中第$K$大的元素是哪一个 题解: 写法很多,主席树是最常用的一种之一 除此之外有:划分树,莫队分块,平衡树等 主席树的定义其实挺模糊, 一般认为就是可持久 ...
- 区间第k大问题 权值线段树 hdu 5249
先说下权值线段树的概念吧 权值平均树 就是指区间维护值为这个区间内点出现次数和的线段树 用这个加权线段树 解决第k大问题就很方便了 int query(int l,int r,int rt,int k ...
随机推荐
- vue中的表单异步校验方法封装
在vue项目的开发中,表单的验证必不可少,在开发的过程中,用的是vue+iview的一套,我们知道iview的表单验证是基于async-validator,对于async-validator不熟悉的可 ...
- 科猫网项目总结(基于SSM框架)
1.配置文件的添加 SSM整合需要web.xml配置文件,springmvc的配置文件,spring和mybatis整合的配置文件. 1.web.xml文件的配置 1.在WEB-INF下新建web.x ...
- js_在原有的日期上添加天数输出添加后的日期
开始编码工作也有段时间了,想想没有留下点什么,有点遗憾.学到的一些经验,写写,分享一下.也给自己整理一下. 今天分享一下,在原有的日期上添加天数输出添加后的日期.开始做的时候,简单的思路是,直接用ne ...
- linux c 执行新程序
学习进程时,linu c上说新开的进程一般要执行另外一个程序,同时与父进程执行同一个程序没有意义 如下是如何执行一个新的程序 使用exec函数簇 exec函数簇包含如下函数
- cacti (可以利用yum安装cacti的配置)
[root@localhost ~]# yum install -y epel-release[root@localhost ~]# [root@localhost ~]# yum install - ...
- C/C++——[01] 程序的基本框架
我们以HelloWorld这个简单程序为例,该程序在终端打印一行文本: Hello World! 代码如下: #include <stdio.h> int main(){ printf(& ...
- python 数据类型 变量 注释
基本数据类型: 数字 number :整数 int . 浮点数 float.复数 complex.布尔值 bool 列表 list : 使用 方括号 [] 表示,例如: [1,2,'abc'] ...
- git清除用户名密码
问题: remote: HTTP Basic: Access deniedfatal: Authentication failed for 'http://******** 解决方案: git con ...
- linux命令(29):cd命令
例1:进入系统根目录 cd / cd ../.. // [直接退到当前根目录] 例2:使用 cd 命令进入当前用户主目录 cd 例3:跳转到指定目录 cd /home/test 例4:返回进入此目 ...
- IllegalStateException: Unable to find a @SpringBootConfiguration
此处需要改掉包名和类名