链接:

https://vjudge.net/problem/HDU-6278

题意:

The h-index of an author is the largest h where he has at least h papers with citations not less than h.

Bobo has published n papers with citations a1,a2,…,an respectively.

One day, he raises q questions. The i-th question is described by two integers li and ri, asking the h-index of Bobo if has only published papers with citations ali,ali+1,…,ari.

思路:

主席树模板,记录每个数字出现的次数,如果某个区间内,数字出现的次数大于等于区间左端点,就往右找,

否则吧右边的所有数累加,往左找,因为右边的数大于左边的数,h是单调的

代码:

#include <iostream>
#include <cstdio>
#include <vector>
#include <memory.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <stack>
using namespace std;
typedef long long LL;
const int MAXN = 1e5+10; struct Segment
{
int cnt;
int l, r;
}Seg[MAXN*30];
int Tree_root[MAXN*30];
int a[MAXN];
int n, m;
int tree_cnt; int Insert(int num, int last, int l, int r)
{
tree_cnt++;
int nownode = tree_cnt;
Seg[tree_cnt].cnt = Seg[last].cnt+1;
int mid = (l+r)/2;
if (l == r)
return nownode;
else if (num <= mid)
{
Seg[nownode].l = Insert(num, Seg[last].l, l, mid);
Seg[nownode].r = Seg[last].r;
}
else
{
Seg[nownode].l = Seg[last].l;
Seg[nownode].r = Insert(num, Seg[last].r, mid+1, r);
}
return nownode;
} int Query(int x, int y, int l, int r, int num)
{
// cout << l << ' ' << r << endl;
if (l == r)
return l;
int mid = (l+r)/2;
int sum = Seg[Seg[y].r].cnt-Seg[Seg[x].r].cnt;
// cout << sum+num << endl;
if (sum+num <= mid)
{
return Query(Seg[x].l, Seg[y].l, l, mid, num+sum);
}
else
{
return Query(Seg[x].r, Seg[y].r, mid+1, r, num);
}
} void Init()
{
tree_cnt = 0;
Seg[0].cnt = 0;
Tree_root[0] = 0;
} int main()
{
while (~scanf("%d %d", &n, &m))
{
for (int i = 1;i <= n;i++)
scanf("%d", &a[i]);
Init();
for (int i = 1;i <= n;i++)
{
int pos = Insert(a[i], Tree_root[i-1], 1, n);
Tree_root[i] = pos;
}
int x, y;
while (m--)
{
scanf("%d %d", &x, &y);
printf("%d\n", Query(Tree_root[x-1], Tree_root[y], 1, n, 0));
}
} return 0;
}
/*
5 3
1 5 3 2 1
1 3
2 4
1 5
5 1000
4 4 4 4 5
1 5
*/

HDU-6278-Jsut$h$-index(主席树)的更多相关文章

  1. HDU 4417 Super Mario(主席树求区间内的区间查询+离散化)

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  2. POJ 2104&HDU 2665 Kth number(主席树入门+离散化)

    K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 50247   Accepted: 17101 Ca ...

  3. hdu 4417 Super Mario (主席树)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4417 题意: 给你段长为n的序列,有q个询问,每次询问区间[l.r]内有多少个数小于等于k 思路: 之前用 ...

  4. hdu 4348 To the moon (主席树)

    版权声明:本文为博主原创文章,未经博主允许不得转载. hdu 4348 题意: 一个长度为n的数组,4种操作 : (1)C l r d:区间[l,r]中的数都加1,同时当前的时间戳加1 . (2)Q ...

  5. HDU 4348 To the moon 主席树 在线更新

    http://acm.hdu.edu.cn/showproblem.php?pid=4348 以前做的主席树没有做过在线修改的题做一下(主席树这种东西正经用法难道不是在线修改吗),标记永久化比较方便. ...

  6. HDU 2665 && POJ 2104(主席树)

    http://poj.org/problem?id=2104 对权值进行建树(这个时候树的叶子是数组b的有序数列),然后二分查找原数列中每个数在有序数列中的位置(即第几小),对每一个前缀[1,i]建一 ...

  7. HDU 5919 -- Sequence II (主席树)

    题意: 给一串数字,每个数字的位置是这个数第一次出现的位置. 每个询问对于序列的一个子区间,设一共有k个不同的数,求第ceil(k/2)个数的位置. 因为强制在线,所以离线乱搞pass掉. 主席树可解 ...

  8. HDU 5919 Sequence II(主席树)题解

    题意:有A1 ~ An组成的数组,给你l r,L = min((l + ans[i - 1]) % n + 1, (r + ans[i - 1]) % n + 1),R = max((l + ans[ ...

  9. HDU 4417 Super Mario(主席树 区间不超过k的个数)题解

    题意:问区间内不超过k的个数 思路:显然主席树,把所有的值离散化一下,然后主席树求一下小于等于k有几个就行.注意,他给你的k不一定包含在数组里,所以问题中的询问一起离散化. 代码: #include& ...

  10. HDU 2665 Kth number(主席树静态区间第K大)题解

    题意:问你区间第k大是谁 思路:主席树就是可持久化线段树,他是由多个历史版本的权值线段树(不是普通线段树)组成的. 具体可以看q学姐的B站视频 代码: #include<cmath> #i ...

随机推荐

  1. C#中winform下利用ArcEngine调用ArcGIS Server发布的服务 AE 10

    开发环境:vs2010 + AE 10 测试 public Form1() { ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Engi ...

  2. RequestContextHolder

    JShop简介:jshop是一套使用Java语言开发的B2C网店系统,致力于为个人和中小企业提供免费.好用的网店系统. 项目主页:http://git.oschina.net/dinguangx/js ...

  3. BigDecimal进行加减乘除计算

    以前大部分关于查询计算的逻辑是在sql语句中执行的,但是有时候会出现比较复杂的计算情况,需要我们在代码中进行计算,这个时候使用BigDecimal进行计算会很方便. BigDecimal num1 = ...

  4. 算法之美&数据结构与算法复习

    1.归并两个有序链表(归并排序) 2.最小路径和--BP解法 3.计算int sqrt(x)--二分解法 4.趣味面试题 5.跳步游戏(Jump_Game)--后向回溯算法 6.Excel列号转十进制 ...

  5. netcat命令用法

    1,端口扫描nc -z -v -n 172.31.100.7 21-25 2,聊天Server:nc -l 1567Client:nc 172.31.100.7 1567 3,文件传输Server:n ...

  6. 如何上传大文件到github上

    真的是被百度坑怕了,只适合我自己的 如果你之前安装git成功的话,右键会出现两个新选项,分别为Git Gui Here,Git Bash Here,这里我们选择Git Bash Here,进入如下界面 ...

  7. Docker最详细入门教程

    Docker原理.详细入门教程 https://blog.csdn.net/deng624796905/article/details/86493330 阮一峰Docker入门讲解 http://ww ...

  8. 指定pom文件jdk版本

    <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> ...

  9. Linux 查看CPU 核数 还有 CPU 个数的命令

    cat /proc/cpuinfo | grep 'physical id' | sort | uniq | wc -l 个数 cat /proc/cpuinfo | grep 'process' | ...

  10. [转帖]socat使用笔记

    socat使用笔记 https://blog.csdn.net/yangbingzhou/article/details/49783235 进行简单学习 centos 下面安装 yum install ...