70tps求条
查看原帖
70tps求条
1034698
jzy_CSPJ_AK楼主2024/11/29 19:41
#include<bits/stdc++.h>
#define rd read()
using namespace std;
const int N = 1e5 + 5;
inline int read(){
	int x = 0, f = 1;
    char ch = getchar();
	while (ch < '0' || ch > '9'){
        if (ch=='-') f = -1;
        ch = getchar();
    }
	while (ch >= '0' && ch <= '9'){
        x = x * 10 + ch - 48;
        ch = getchar();
    }
	return x*f;
}
int st[N][28], lg[N], n, m, r, l;
int q(int l, int r){
    int k = lg[r - l + 1];
    return max(st[l][k], st[r - (1 << k) + 1][k]);
}
signed main(){
    ios::sync_with_stdio(false);cin.tie(0);
    n = rd, m = rd;
    for(int i = 2;i <= n;i ++) lg[i] = lg[i / 2] + 1;
    for(int i = 1;i <= n;i ++)st[i][0] = rd;
    for(int j = 1;j <= 22;j ++){
        for(int i = 1;i + (1 << j) - 1 <= n;i ++){
            st[i][j] = max(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
        }
    }
    for(int i = 1;i <= m;i ++){
        l = rd, r = rd;
        cout << q(l, r) << endl;
    }
    return 0;
}
2024/11/29 19:41
加载中...