忠诚2 | ||
|
#include<cstdio>
#include<cstring>
int n,m;
int a[100010];
#define LL(x) (x<<1)
#define RR(x) (x<<1|1)
#define min(a,b) a>b?b:a
struct TREE
{
int left,right;
int rmin;
int mid() { return ((left+right)>>1);}
}tree[100010*3];
void build(int l,int r,int idx)
{
tree[idx].left=l;
tree[idx].right=r;
if(tree[idx].left==tree[idx].right)
{
tree[idx].rmin=a[l];
return ;
}
int mid=tree[idx].mid();
build(l,mid,LL(idx));
build(mid+1,r,RR(idx));
tree[idx].rmin=min(tree[LL(idx)].rmin,tree[RR(idx)].rmin);
}
void update(int x,int y,int idx)
{
if(tree[idx].left==tree[idx].right)
{
tree[idx].rmin=y;
return;
}
int mid=tree[idx].mid();
if(x<=mid) update(x,y,LL(idx));
else if(x>mid) update(x,y,RR(idx));
tree[idx].rmin=min(tree[LL(idx)].rmin,tree[RR(idx)].rmin);
}
int query(int l,int r,int idx)
{
if(l<=tree[idx].left&&tree[idx].right<=r)
{
return tree[idx].rmin;
}
int mid=tree[idx].mid();
if(l>mid) return query(l,r,RR(idx));
else if(r<=mid) return query(l,r,LL(idx));
else return min( query(l,mid,LL(idx)) , query(mid+1,r,RR(idx)));
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
build(1,n,1);
int a,x,y;
int num=0;
for(int i=1;i<=m;i++)
{
scanf("%d%d%d",&a,&x,&y);
if(a==1)
{
if(num!=0) printf(" ");
num=1;
printf("%d",query(x,y,1));
}
else
{
update(x,y,1);
}
}
printf("/n");
return 0;
}