链接:

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. Linux_KVM虚拟机

    目录 目录 Hpyervisor的种类 安装KVM 使用virsh指令管理虚拟机 KVM虚拟机的网络设置 Hpyervisor的种类 hpyervisor:是一种VMM(Virtual Machine ...

  2. eslint+prettier 的 VSCode配置项

    { "files.autoSave": "off", "editor.fontSize": 12, "terminal.integ ...

  3. Vue模版编译

    一 模版文件 <div> <header> <h1>I'm a template!</h1> </header> <p v-if=&q ...

  4. Django-DRF组件学习-预备知识

    1.web开发应用模式 在开发Web应用中,有两种应用模式: 1.1 前后端不分离 所谓的前后端不分离,就是前后端数据都在同一个服务器中,前端的样式以及页面渲染都由后端一次性渲染出来在前端浏览器中展示 ...

  5. python 使用 with open() as 读写文件

    读文件: 要以读文件的模式打开一个文件对象,使用Python内置的open()函数,传入文件名和标示符: >>> f = open('E:\python\python\test.tx ...

  6. 多线程15-ReaderWriterLockSlim

        ));         }         );                     rwl.EnterUpgradeableReadLock();                     ...

  7. Ubuntu 16.04简单配置备忘录

    1.几个安装包的地址 1.Linux QQ:https://im.qq.com/linuxqq/index.html 2.网易云音乐:http://s1.music.126.net/download/ ...

  8. JS之理解继承

    JS之理解继承:https://segmentfault.com/a/1190000010468293 1.call继承,也叫借用构造函数.伪造对象或是经典继承.call继承回把父类的私有属性和方法继 ...

  9. [HDU 3712] Fiolki (带边权并查集+启发式合并)

    [HDU 3712] Fiolki (带边权并查集+启发式合并) 题面 化学家吉丽想要配置一种神奇的药水来拯救世界. 吉丽有n种不同的液体物质,和n个药瓶(均从1到n编号).初始时,第i个瓶内装着g[ ...

  10. python字符串 常用函数 格式化字符串 字符串替换 制表符 换行符 删除空白 国际货币格式

    # 字符串常用函数# 转大写print('bmw'.upper()) # BMW# 转小写print('BMW'.lower()) # bmw# 首字母大写print('how aae you ?'. ...