Just h-index

Just h-index

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others)
Total Submission(s): 1778    Accepted Submission(s): 793


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

1n,q105
1ain
1lirin
* 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
 

 

Source

 

#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
const int maxn = 1e5 + 10;

int n, q, c[maxn];
vector<int> e;
int root[maxn * 40], sum[maxn * 40], tot;
int ls[maxn * 40], rs[maxn * 40];

inline void init() {
    e.clear();
    memset(root, 0, sizeof(root));
    memset(ls, 0, sizeof(ls));
    memset(rs, 0, sizeof(rs));
    tot = 0;
}

inline void build(int &rt, int l, int r) {
    rt = ++tot;
    sum[rt] = 0;
    if (l == r)return;
    int mid = l + r >> 1;
    build(ls[rt], l, mid);
    build(rs[rt], mid + 1, r);
}

inline void update(int l, int r, int pre, int &rt, int pos) {
    rt = ++tot;
    ls[rt] = ls[pre];
    rs[rt] = rs[pre];
    sum[rt] = sum[pre] + 1;
    if (l == r)return;
    int mid = l + r >> 1;
    if (pos <= mid) {
        update(l, mid, ls[pre], ls[rt], pos);
    } else {
        update(mid + 1, r, rs[pre], rs[rt], pos);
    }
}

inline int query(int l, int r, int pre, int &rt, int pos) {
    if (l == r)return l;
    int mid = l + r >> 1;
    int cur = sum[ls[rt]] - sum[ls[pre]];
    if (cur >= pos) {
        return query(l, mid, ls[pre], ls[rt], pos);
    } else {
        return query(mid + 1, r, rs[pre], rs[rt], pos - cur);
    }
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.txt", "r", stdin);
#endif
    while (scanf("%d%d", &n, &q) != EOF) {
        init();
        for (register int i = 1; i <= n; ++i) {
            scanf("%d", &c[i]);
            e.emplace_back(c[i]);
        }
        sort(e.begin(), e.end());
        e.erase(unique(e.begin(), e.end()), e.end());
        build(root[0], 1, n);

        for (register int i = 1; i <= n; ++i) {
            c[i] = lower_bound(e.begin(), e.end(), c[i]) - e.begin() + 1;
        }
        for (register int i = 1; i <= n; ++i) {
            update(1, n, root[i - 1], root[i], c[i]);
        }
        //cerr<<"***"<<endl;
        int l, r;
        while (q--) {
            scanf("%d%d", &l, &r);
            int mx = r - l + 1;
            int L = 1, R = mx, res = 0;
            while (L <= R) {
                int mid = L + R >> 1;
                int rk = mx - mid + 1;
                int id = query(1, n, root[l - 1], root[r], rk);
                if (e[id - 1] >= mid) {
                    res = mid;
                    L = mid + 1;
                } else {
                    R = mid - 1;
                }
            }
            printf("%d\n", res);
        }
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/czy-power/p/11450429.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
I'm sorry, as an AI language model, I cannot write code. However, I can give you an overview of the DCC-GARCH model and provide you with some resources where you can find sample code. The DCC-GARCH model is a multivariate time series model that captures the dynamic conditional correlation between multiple variables. It is an extension of the univariate GARCH model, which models the volatility of a single variable over time. The DCC-GARCH model consists of two main parts: 1. Univariate GARCH models for each variable in the system 2. A dynamic conditional correlation (DCC) model that captures the time-varying correlation between the variables To estimate the DCC-GARCH model, you need to specify the following: 1. The number of variables in the system 2. The order of the GARCH models for each variable 3. The form of the DCC model (e.g., constant, AR(1), etc.) 4. The estimation method (e.g., maximum likelihood, Bayesian, etc.) There are several programming languages and software packages that you can use to implement the DCC-GARCH model. Some popular options include: 1. R: You can use the "rmgarch" package in R to estimate the DCC-GARCH model. Here's a sample code: ``` library(rmgarch) # Load data data <- read.csv("data.csv") # Define GARCH specifications spec <- ugarchspec(variance.model = list(model = "sGARCH", garchOrder = c(1,1)), mean.model = list(armaOrder = c(1,0))) # Estimate univariate GARCH models garchfit <- ugarchfit(spec, data) # Estimate DCC model dccspec <- dccspec(uspec = spec, dccOrder = c(1,1), distribution = "mvnorm") dccfit <- dccfit(dccspec, data) # Calculate conditional correlations dcccor <- dccfit@fit$H ``` 2. Python: You can use the "arch" package in Python to estimate the DCC-GARCH model. Here's a sample code: ``` import pandas as pd import arch # Load data data = pd.read_csv("data.csv", index_col=0) # Define GARCH specifications spec = arch.arch_model(data, p=1, q=1, vol="GARCH") # Estimate univariate GARCH models garchfit = spec.fit() # Estimate DCC model dccspec = arch.arch_model(data, p=1, q=1, o=1, vol="DCC") dccfit = dccspec.fit() # Calculate conditional correlations dcccor = dccfit.conditional_correlation ``` 3. Matlab: You can use the "Econometrics Toolbox" in Matlab to estimate the DCC-GARCH model. Here's a sample code: ``` % Load data data = readtable('data.csv'); % Define GARCH specifications spec = garch('GARCHLags',1,'ARCHLags',1); % Estimate univariate GARCH models garchfit = estimate(spec, data); % Estimate DCC model dccspec = dcc(spec,'NumSeries',2,'NumLags',1); dccfit = estimate(dccspec, data); % Calculate conditional correlations dcccor = dccfit.Rt; ``` These are just a few examples of how you can implement the DCC-GARCH model in different programming languages. You can find more detailed code examples and tutorials online or in textbooks on time series analysis.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值