HDU 6278 - Just h-index - [莫队算法+树状数组+二分][2018JSCPC江苏省赛C题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6278
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Others)
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.
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.
## 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.
题意:
一个作者它的“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代码:
#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e5+;
const int MAXM=1e5+; int n,m;
int citation[MAXN];
int h_idx[MAXM];
struct Query
{
int block;
int id;
int l,r;
bool operator <(const Query &oth) const
{
if(block==oth.block) return r<oth.r;
return block<oth.block;
}
}query[MAXM]; struct _BIT{
int N,C[MAXN];
int lowbit(int x){return x&(-x);}
void init(int n)//初始化共有n个点
{
N=n;
for(int i=;i<=N;i++) C[i]=;
}
void add(int pos,int val)//在pos点加上val
{
while(pos<=N)
{
C[pos]+=val;
pos+=lowbit(pos);
}
}
int sum(int pos)//查询1~pos点的和
{
int ret=;
while(pos>)
{
ret+=C[pos];
pos-=lowbit(pos);
}
return ret;
}
}BIT; int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
int len=sqrt(n);
for(int i=;i<=n;i++) scanf("%d",&citation[i]); for(int i=;i<=m;i++)
{
scanf("%d%d",&query[i].l,&query[i].r);
query[i].block=query[i].l/len;
query[i].id=i;
}
sort(query+,query+m+); BIT.init(n);
int pl=;
int pr=;
int cnt=;
for(int i=;i<=m;i++)
{
if(pr<query[i].r)
{
for(int j=pr+;j<=query[i].r;j++)
{
BIT.add(citation[j],);
cnt++;
}
}
if(pr>query[i].r)
{
for(int j=pr;j>query[i].r;j--)
{
BIT.add(citation[j],-);
cnt--;
}
}
if(pl<query[i].l)
{
for(int j=pl;j<query[i].l;j++)
{
BIT.add(citation[j],-);
cnt--;
}
}
if(pl>query[i].l)
{
for(int j=pl-;j>=query[i].l;j--)
{
BIT.add(citation[j],);
cnt++;
}
}
pl=query[i].l;
pr=query[i].r; int l=,r=n,mid;
while(l<r)
{
mid=(l+r+)/;
if(cnt-BIT.sum(mid-)<mid) r=mid-;
else l=mid;
} h_idx[query[i].id]=r;
} for(int i=;i<=m;i++) printf("%d\n",h_idx[i]);
}
}
HDU 6278 - Just h-index - [莫队算法+树状数组+二分][2018JSCPC江苏省赛C题]的更多相关文章
- 【bzoj3289】Mato的文件管理 离散化+莫队算法+树状数组
原文地址:http://www.cnblogs.com/GXZlegend/p/6805224.html 题目描述 Mato同学从各路神犇以各种方式(你们懂的)收集了许多资料,这些资料一共有n份,每份 ...
- HDU-6534-Chika and Friendly Pairs (莫队算法,树状数组,离散化)
链接: https://vjudge.net/contest/308446#problem/C 题意: Chika gives you an integer sequence a1,a2,-,an a ...
- BZOJ3289 Mato的文件管理(莫队算法+树状数组)
题目是区间逆序数查询. 莫队算法..左或右区间向左或右延伸时加或减这个区间小于或大于新数的数的个数,这个个数用树状数组来统计,我用线段树超时了.询问个数和数字个数都记为n,数字范围不确定所以离散化,这 ...
- 【BZOJ3289】Mato的文件管理 莫队算法+树状数组
[BZOJ3289]Mato的文件管理 Description Mato同学从各路神犇以各种方式(你们懂的)收集了许多资料,这些资料一共有n份,每份有一个大小和一个编号.为了防止他人偷拷,这些资料都是 ...
- BZOJ3289【莫队算法+树状数组+离散化】
思路: 区间逆序数即是交换次数. 逆序数,可以用树状数组吧. 怎么处理区间变换的时候求逆序数啊.. 这里分成左边的增/删,右边的增/删 因为是按时序插入, 所以左边增,增一个数,计算:ans+=sun ...
- BZOJ 3289:Mato的文件管理(莫队算法+树状数组)
http://www.lydsy.com/JudgeOnline/problem.php?id=3289 题意:…… 思路:求交换次数即求逆序对数.确定了这个之后,先离散化数组.然后在后面插入元素的话 ...
- BZOJ 3289: Mato的文件管理[莫队算法 树状数组]
3289: Mato的文件管理 Time Limit: 40 Sec Memory Limit: 128 MBSubmit: 2399 Solved: 988[Submit][Status][Di ...
- 【BZOJ】3289: Mato的文件管理(莫队算法+树状数组)
http://www.lydsy.com/JudgeOnline/problem.php?id=3289 很裸的莫队... 离线了区间然后分块排序后,询问时搞搞就行了. 本题中,如果知道$[l, r] ...
- BZOJ 2120: 数颜色 带修改的莫队算法 树状数组套主席树
https://www.lydsy.com/JudgeOnline/problem.php?id=2120 标题里是两种不同的解法. 带修改的莫队和普通莫队比多了个修改操作,影响不大,但是注意一下细节 ...
随机推荐
- iOS Runloop的超级讲解
这是目前看过的最好的一片中文讲解RunLoop的文章,推荐给大家看一下,原文链接:http://blog.ibireme.com/2015/05/18/runloop/ https://segment ...
- 【AI】face_recognition
1.pip install cmake 2.pip install boost 3.pip install dlib 4.pip install face_recognition
- laravel 5.3升级5.4
1)修改 composer 配置文件 composer.json 1.如果你用了 laravel-admin,larvel-admin 版本改 1.4.x-dev 2.laravel 版本改 5.4. ...
- Python中执行外部命令
有很多需求需要在Python中执行shell命令.启动子进程,并捕获命令的输出和退出状态码,类似于Java中的Runtime类库. subprocess模块的使用: Python使用最广泛的是标准库的 ...
- CentOS7--Firewalld防火墙
Firewalld服务是红帽RHEL7系统中默认的防火墙管理工具,特点是拥有运行时配置与永久配置选项且能够支持动态更新以及"zone"的区域功能概念,使用图形化工具firewall ...
- CentOS6.5下安装Oracle11g
一.安装前系统准备 1. 修改主机名 #sed -i "s/HOSTNAME=localhost.localdomain/HOSTNAME=oracledb.01/" /etc/s ...
- [Python] io 模块之 open() 方法
io.open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True) 打开file ...
- React Native(十二)——嵌套WebView中的返回处理
情景描述: 从一个名为"My"的组件点击进去,进入一个列表(该列表内容为webView中内容),其中一个webView也可以点击进入详情页(也为webView),但是如果对导航栏不 ...
- 对C#中几个循环语句的使用,请教
今天是在云和数据学院学习的第四天,由于各种原因···今天自己预习的循环语句的用法以及写了几个程序,也遇到各种的问题了···纠结.由于还是在学习的很初初初级,所以好多简单的方法还是不知道怎么写出来,只得 ...
- Foxmail邮箱最新应用指南二
Foxmail邮箱最新应用指南二 1.打开Foxmail主界面—工具—账号管理,或者鼠标右击任何已有账号—属性,弹出账号管理窗口,点击左下角的“新建”按钮: 2.输入邮箱地址,下一步→选择邮箱类型(I ...