满江红,解决悬关
  • 板块P1816 忠诚
  • 楼主Jasonshan10
  • 当前回复3
  • 已保存回复3
  • 发布时间2023/9/24 14:44
  • 上次更新2023/11/2 18:19:45
查看原帖
满江红,解决悬关
782125
Jasonshan10楼主2023/9/24 14:44
#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e5+5;
int st[MAXN][25];
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<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}
int main(){
	int n=read(),m=read();
	for(register int i=1;i<=n;++i){
		st[i][0]=read();
	}
	for(register int j=1;j<=21;++j){
		for(register int i=1;i+(1<<j)-1<=n;++i){
			st[i][j]=min(st[i][j-1],st[i+(1<<(j-1))][j-1]);
		}
	}
	while (m--){
		int l=read(),r=read();
		int k=log2(r-l+1);
		printf("%d\n",min(st[l][k],st[r-(1<<k)+1][k]));
	}
	return 0;
}
2023/9/24 14:44
加载中...