题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6278

Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others)

Problem Description

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.

 
Input

The input consists of several test cases and is terminated by end-of-file.
The first line of each test case contains two integers n and q.
The second line contains n integers a1,a2,…,an.
The i-th of last q lines contains two integers li and ri.

 
Output
For each question, print an integer which denotes the answer.

## Constraint

* 1≤n,q≤105
* 1≤ai≤n
* 1≤li≤ri≤n
* The sum of n does not exceed 250,000.
* The sum of q does not exceed 250,000.

 
Sample Input
5 3
1 5 3 2 1
1 3
2 4
1 5
5 1
1 2 3 4 5
1 5
 
Sample Output
2
2
2
3

题意:

一个作者它的“h-index”指的是:有一个最大的正整数h,且满足他有至少h篇论文的引用量不低于h。

现在给出n篇论文的引用量,m个区间[L,R]的查询,询问假设他只发了[L,R]这个区间内的这些论文,则他的h-index为多少。

题解:

当初比赛的时候不会主席树,也不会莫队,只能拿着普通的线段树在那里硬刚,结果十分凄惨。

现在会了分块版的莫队算法,回来补题了。

考虑num[c]表示引用量为c的文章数,那么用树状数组维护就可以 $O\left( {\log _2 N} \right)$ 的进行单点修改、区间查询,正好符合题目要求;

所以我们每次区间转移进行 $O\left( {\log _2 N} \right)$ 的进行单点修改,

然后转移结束之后,当前区间的答案(h_index)就可以通过 二分查找 + $O\left( {\log _2 N} \right)$ 的区间查询 得到。

时间复杂度大概在 $O\left( {N \cdot \sqrt N \cdot \left( {\log _2 N} \right)^2 } \right)$,从理论上讲应该可以过。

AC代码:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int MAXN=1e5+;
  4. const int MAXM=1e5+;
  5.  
  6. int n,m;
  7. int citation[MAXN];
  8. int h_idx[MAXM];
  9. struct Query
  10. {
  11. int block;
  12. int id;
  13. int l,r;
  14. bool operator <(const Query &oth) const
  15. {
  16. if(block==oth.block) return r<oth.r;
  17. return block<oth.block;
  18. }
  19. }query[MAXM];
  20.  
  21. struct _BIT{
  22. int N,C[MAXN];
  23. int lowbit(int x){return x&(-x);}
  24. void init(int n)//初始化共有n个点
  25. {
  26. N=n;
  27. for(int i=;i<=N;i++) C[i]=;
  28. }
  29. void add(int pos,int val)//在pos点加上val
  30. {
  31. while(pos<=N)
  32. {
  33. C[pos]+=val;
  34. pos+=lowbit(pos);
  35. }
  36. }
  37. int sum(int pos)//查询1~pos点的和
  38. {
  39. int ret=;
  40. while(pos>)
  41. {
  42. ret+=C[pos];
  43. pos-=lowbit(pos);
  44. }
  45. return ret;
  46. }
  47. }BIT;
  48.  
  49. int main()
  50. {
  51. while(scanf("%d%d",&n,&m)!=EOF)
  52. {
  53. int len=sqrt(n);
  54. for(int i=;i<=n;i++) scanf("%d",&citation[i]);
  55.  
  56. for(int i=;i<=m;i++)
  57. {
  58. scanf("%d%d",&query[i].l,&query[i].r);
  59. query[i].block=query[i].l/len;
  60. query[i].id=i;
  61. }
  62. sort(query+,query+m+);
  63.  
  64. BIT.init(n);
  65. int pl=;
  66. int pr=;
  67. int cnt=;
  68. for(int i=;i<=m;i++)
  69. {
  70. if(pr<query[i].r)
  71. {
  72. for(int j=pr+;j<=query[i].r;j++)
  73. {
  74. BIT.add(citation[j],);
  75. cnt++;
  76. }
  77. }
  78. if(pr>query[i].r)
  79. {
  80. for(int j=pr;j>query[i].r;j--)
  81. {
  82. BIT.add(citation[j],-);
  83. cnt--;
  84. }
  85. }
  86. if(pl<query[i].l)
  87. {
  88. for(int j=pl;j<query[i].l;j++)
  89. {
  90. BIT.add(citation[j],-);
  91. cnt--;
  92. }
  93. }
  94. if(pl>query[i].l)
  95. {
  96. for(int j=pl-;j>=query[i].l;j--)
  97. {
  98. BIT.add(citation[j],);
  99. cnt++;
  100. }
  101. }
  102. pl=query[i].l;
  103. pr=query[i].r;
  104.  
  105. int l=,r=n,mid;
  106. while(l<r)
  107. {
  108. mid=(l+r+)/;
  109. if(cnt-BIT.sum(mid-)<mid) r=mid-;
  110. else l=mid;
  111. }
  112.  
  113. h_idx[query[i].id]=r;
  114. }
  115.  
  116. for(int i=;i<=m;i++) printf("%d\n",h_idx[i]);
  117. }
  118. }

HDU 6278 - Just h-index - [莫队算法+树状数组+二分][2018JSCPC江苏省赛C题]的更多相关文章

  1. 【bzoj3289】Mato的文件管理 离散化+莫队算法+树状数组

    原文地址:http://www.cnblogs.com/GXZlegend/p/6805224.html 题目描述 Mato同学从各路神犇以各种方式(你们懂的)收集了许多资料,这些资料一共有n份,每份 ...

  2. HDU-6534-Chika and Friendly Pairs (莫队算法,树状数组,离散化)

    链接: https://vjudge.net/contest/308446#problem/C 题意: Chika gives you an integer sequence a1,a2,-,an a ...

  3. BZOJ3289 Mato的文件管理(莫队算法+树状数组)

    题目是区间逆序数查询. 莫队算法..左或右区间向左或右延伸时加或减这个区间小于或大于新数的数的个数,这个个数用树状数组来统计,我用线段树超时了.询问个数和数字个数都记为n,数字范围不确定所以离散化,这 ...

  4. 【BZOJ3289】Mato的文件管理 莫队算法+树状数组

    [BZOJ3289]Mato的文件管理 Description Mato同学从各路神犇以各种方式(你们懂的)收集了许多资料,这些资料一共有n份,每份有一个大小和一个编号.为了防止他人偷拷,这些资料都是 ...

  5. BZOJ3289【莫队算法+树状数组+离散化】

    思路: 区间逆序数即是交换次数. 逆序数,可以用树状数组吧. 怎么处理区间变换的时候求逆序数啊.. 这里分成左边的增/删,右边的增/删 因为是按时序插入, 所以左边增,增一个数,计算:ans+=sun ...

  6. BZOJ 3289:Mato的文件管理(莫队算法+树状数组)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3289 题意:…… 思路:求交换次数即求逆序对数.确定了这个之后,先离散化数组.然后在后面插入元素的话 ...

  7. BZOJ 3289: Mato的文件管理[莫队算法 树状数组]

    3289: Mato的文件管理 Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 2399  Solved: 988[Submit][Status][Di ...

  8. 【BZOJ】3289: Mato的文件管理(莫队算法+树状数组)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3289 很裸的莫队... 离线了区间然后分块排序后,询问时搞搞就行了. 本题中,如果知道$[l, r] ...

  9. BZOJ 2120: 数颜色 带修改的莫队算法 树状数组套主席树

    https://www.lydsy.com/JudgeOnline/problem.php?id=2120 标题里是两种不同的解法. 带修改的莫队和普通莫队比多了个修改操作,影响不大,但是注意一下细节 ...

随机推荐

  1. 用python开发android应用 【转载】

    用python开发android应用 [转载] 转载自:http://www.miui.com/thread-995114-1-1.html Python是动态语言,比较简洁.Android不直接支持 ...

  2. VMWare------安装时出现无法将值写入注册表项

    安装时提示详情: 无法打开注册表项UNKNOWN\Components\...请确认你是否有足够的权限访问该注册表项,或者与技术支持人员联系. 解决方法: 关掉360安全卫士等软件再安装

  3. 8 -- 深入使用Spring -- 3...1 Resource实现类InputStreamResource、ByteArrayResource

    8.3.1 Resource实现类------InputStreamResource:访问输入流资源的实现类.ByteArrayResource:访问字节数组资源的实现类. 5. 访问字节数组资源 ⊙ ...

  4. Log4net用法(.config文件)

    1.引用log4net.dll 2.在AssemblyInfo.cs中添加初始化: [assembly: log4net.Config.XmlConfigurator(ConfigFile = &qu ...

  5. java的子类覆盖梗

    项目上线,用户注册时验证码一直报错误,数据库也没问题,代码貌似也没问题. 后面排查到最后,发现是一个子类覆盖父属性问题. JAVA代码中,子类覆盖父类的私有.保护属性,如果不设置get.set方法,拿 ...

  6. Python对象(下)

    前面一篇文章介绍了一些Python对象的基本概念,这篇接着来看看Python对象相关的一些内容. Python对象的比较 Python对象有三个要素:身份,类型和值,所以我们就分别从这三个角度出发看看 ...

  7. python关键字与标识符

    编程语言众多,但每种语言都有相应的关键字,Python 也不例外,它自带了一个 keyword 模块,用于检测关键字. 关键字列表 进入 Python 交互模式,获取关键字列表: >>&g ...

  8. 【代码审计】CLTPHP_v5.5.3后台任意文件删除漏洞分析

      0x00 环境准备 CLTPHP官网:http://www.cltphp.com 网站源码版本:CLTPHP内容管理系统5.5.3版本 程序源码下载:https://gitee.com/chich ...

  9. Nginx SSL配置

    一.SSL 原理 ① 客户端( 浏览器 )发送一个 https 请求给服务器② 服务器要有一套证书,其实就是公钥和私钥,这套证书可以自己生成,也可以向组织申请,服务器会把公钥传输给客户端③ 客户端收到 ...

  10. 使用 urllib 进行身份验证

    如下图,有些网站需要使用用户名密码才可以登录,我们可以使用 HTTPBasicAuthHandler() 来实现 from urllib.request import HTTPPasswordMgrW ...