#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
struct node{
int l,r,Min;
}tree[30000*4];
void build(int num,int l,int r){
tree[num].l=l;
tree[num].r=r;
if(l==r){
scanf("%d",&tree[num].Min);
return;
}
int mid=(l+r)/2;
build(num*2,l,mid);
build(num*2+1,mid+1,r);
tree[num].Min=min(tree[num*2].Min,tree[num*2+1].Min);
}
int query(int num,int l,int r){
if(tree[num].l>=l && tree[num].r<=r)return tree[num].Min;
int mid=(tree[num].l+tree[num].r)/2;
if(r<=mid)return query(num*2,l,r);
else if(l>mid)return query(num*2+1,l,r);
else return min(query(num*2,l,mid),query(num*2+1,mid+1,r));
}
int n,m;
int main(){
scanf("%d%d",&n,&m);
build(1,1,n);
for(int i=0; i<m; i++){
int x,y;
scanf("%d%d",&x,&y);
printf("%d\n",query(1,x,y));
}
return 0;
}
13381:[Usaco2004 Open]Cave Cows 2 洞穴里的牛之二
最新推荐文章于 2024-09-04 21:39:45 发布