HDU-6278 Just h-index (主席树+二分)

主席树求解H指数问题
本文介绍了一种使用主席树解决H指数问题的方法。H指数是指作者最大的h值,使得他至少有h篇论文被引用次数不低于h次。文章详细阐述了如何通过二分枚举和主席树查询,来高效地在指定区间内找到满足条件的最大H指数。

题目描述

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

Bobo has published n papers with citations a1,a2,…,ana_1,a_2,…,a_na1,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,…,aria_{l_i},a_{l_{i+1}},…,a_{r_i}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 nnn and qqq.
The second line contains n integers a1,a2,…,ana_1,a_2,…,a_na1,a2,,an.
The iii-th of last qqq lines contains two integers lil_ili and rir_iri.

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

Constraint

  • 1≤n,qn,qn,q≤105
  • 1≤aia_iai≤n
  • 1≤lil_ilirir_iri≤n
  • The sum of nnn does not exceed 250,000.
  • The sum of qqq does not exceed 250,000.

题解

给定序列a, 在指定区间[L,R][L,R][L,R]中找到最大的数字h,使其满足在a[L] ~ a[R]范围内大于等于h的数字不少于h个。
需要涉及区间内有序的问题,可以想到用主席树来做。

二分枚举h,用主席树查找在区间内大于等于h的数字个数是否大于等于h.

(代码借鉴学长lcy大佬,lcytql)





#include<bits/stdc++.h>
using namespace std;
const long long maxn=1e6+10;

struct node{
    int sum;
    int l,r;
}tree[maxn*30];

void reset(int x){
    //这个函数真的 女少 啊,把0节点直接代替初始空线段树所有的节点
    tree[x].sum = 0;
    tree[x].l = tree[x].r = 0;
}

int root[maxn], tot;
int n,q;

int build(int l, int r, int old, int x){
    tot++;
    int temp = tot;
    tree[tot] = tree[old];
    tree[tot].sum++;
    if(l==r) return temp;
    int mid = (l+r)>>1;
    if(x<=mid)
        tree[temp].l=build(l, mid, tree[old].l,x);
    else
        tree[temp].r=build(mid+1, r, tree[old].r, x);
    return temp;
}

int query(int l, int r, int lrt, int rrt, int x){
    if(l==r)
        return tree[rrt].sum - tree[lrt].sum;
    int mid=(l+r)>>1;
    if(x>mid)
        return query(mid+1, r, tree[lrt].r, tree[rrt].r, x);
    else{
        int rr = tree[rrt].r, lr = tree[lrt].r;
        return tree[rr].sum - tree[lr].sum + query(l, mid, tree[lrt].l, tree[rrt].l, x);
    } //如果h在区间mid右边,则大于h的区间仍然在右子树上,搜索右子树。
  //否则整个右子树的值都是大于h的一部分,并且在h到mid间也可能存在大于h的数,继续搜索左子树。
}

int solve(int x, int y){
    int l, r, mid, ans;
    ans = 1;
    l = 1;
    r = n;
    while(l<=r){
        mid = (l+r)>>1;
        if(query(1, n, root[x-1], root[y], mid) >= mid){
            ans = mid;
            l = mid + 1;
        }else{
            r = mid - 1;
        }
    }
    return ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    //freopen("test.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    
    while(cin>>n>>q){
        tot=0;
        reset(0);
        for(int i=1;i<=n;i++){
            int x;
            cin>>x;
            root[i]=build(1,n,root[i-1],x);
        }
        for(int i=1;i<=q;i++){
            int l,r;
            cin >> l >> r;
            cout<<solve(l,r)<<endl;
        }
    }
    
    return 0;
}
基于数据驱动的 Koopman 算子的递归神经网络模型线性化,用于纳米定位系统的预测控制研究(Matlab代码实现)内容概要:本文围绕“基于数据驱动的Koopman算子的递归神经网络模型线性化”展开,旨在研究纳米定位系统的预测控制方法。通过结合数据驱动技术与Koopman算子理论,将非线性系统动态近似为高维线性系统,进而利用递归神经网络(RNN)建模并实现系统行为的精确预测。文中详细阐述了模型构建流程、线性化策略及在预测控制中的集成应用,并提供了完整的Matlab代码实现,便于科研人员复现实验、优化算法并拓展至其他精密控制系统。该方法有效提升了纳米级定位系统的控制精度与动态响应性能。; 适合人群:具备自动控制、机器学习或信号处理背景,熟悉Matlab编程,从事精密仪器控制、智能制造或先进控制算法研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①实现非线性动态系统的数据驱动线性化建模;②提升纳米定位平台的轨迹跟踪与预测控制性能;③为高精度控制系统提供可复现的Koopman-RNN融合解决方案; 阅读建议:建议结合Matlab代码逐段理解算法实现细节,重点关注Koopman观测矩阵构造、RNN训练流程与模型预测控制器(MPC)的集成方式,鼓励在实际硬件平台上验证并调整参数以适应具体应用场景。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值