91pts求助(玄关)
  • 板块P1816 忠诚
  • 楼主kanzaki
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/11/15 20:32
  • 上次更新2023/11/15 21:51:56
查看原帖
91pts求助(玄关)
1054608
kanzaki楼主2023/11/15 20:32

#9 WA了,其他点全过

#include <bits/stdc++.h>
using namespace std;
#define maxn 200005
#define ll long long
#define int long long
#define inf 0x7fffffff
ll a[maxn],w[maxn*4];
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-'0';
		ch=getchar();
	}
	return x*f;
}//快读 
void write(int x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
}//快写
void pushup(int u){
	w[u]=min(w[u*2],w[u*2+1]);
}
void build(int u,int L,int R){
	if(L==R) w[u]=a[L];
	else {
		int M=(R+L)/2;
		build(u*2,L,M),build(u*2+1,M+1,R);
		pushup(u);
	}
}
bool inrange(int L,int R,int l,int r){
	return (l<=L)&&(R<=r);
}
bool outofrange(int L,int R,int l,int r){
	return (L>r)||(R<l);
}
ll query(int u,int L,int R,int l,int r){
	if(inrange(L,R,l,r)) return w[u];
	else if(!outofrange(L,R,l,r)){
		int M=(R+L)/2;
		return min(query(u*2,L,M,l,r),query(u*2+1,M+1,R,l,r));
	}
	return inf;
}
int m,n,x,y;
signed main(){
//	memset(w,inf-5,sizeof(w));
	m=read(),n=read();
	for(int i=1;i<=m;i++){
		a[i]=read();
	}
	build(1,1,n);
	for(int i=1;i<=n;i++){
		x=read(),y=read();
		write(query(1,1,n,x,y));
		cout<<" ";
	}
	return 0;
}
2023/11/15 20:32
加载中...