10 3
1 2 3 4 5 6 7 8 9 10
1 2 7
2 2 0
1 1 10
2 0
线段树维护最小值
【代码】
#include<iostream> #include<cstring> #include<cstdio> #define inf 2100000000 using namespace std; int n,m,ans,lrange,rrange,x,v,ty; int a[100005],sum[300005]; inline void update(int now){ sum[now]=min(sum[now<<1],sum[(now<<1)+1]); } inline void build(int now,int l,int r){ int mid=(l+r)>>1; if (l==r){ sum[now]=a[l]; return; } build(now<<1,l,mid); build((now<<1)+1,mid+1,r); update(now); } inline void point_change(int now,int l,int r,int x,int v){ int mid=(l+r)>>1; if (l==r){ sum[now]=v; return; } if (x<=mid) point_change(now<<1,l,mid,x,v); else point_change((now<<1)+1,mid+1,r,x,v); update(now); } inline int query(int now,int l,int r,int lrange,int rrange){ int mid=(l+r)>>1,ans=inf; if (lrange<=l&&r<=rrange) return sum[now]; if (lrange<=mid) ans=min(ans,query(now<<1,l,mid,lrange,rrange)); if (mid+1<=rrange) ans=min(ans,query((now<<1)+1,mid+1,r,lrange,rrange)); return ans; } int main(){ freopen("a.in","r",stdin); freopen("a.out","w",stdout); scanf("%d%d",&n,&m); for (int i=1;i<=n;++i) scanf("%d",&a[i]); build(1,1,n); for (int i=1;i<m;++i){ scanf("%d",&ty); if (ty==1){ scanf("%d%d",&lrange,&rrange); ans=query(1,1,n,lrange,rrange); printf("%d ",ans); } if (ty==2){ scanf("%d%d",&x,&v); point_change(1,1,n,x,v); } } scanf("%d",&ty); if (ty==1){ scanf("%d%d",&lrange,&rrange); ans=query(1,1,n,lrange,rrange); printf("%d\n",ans); } if (ty==2){ scanf("%d%d",&x,&v); point_change(1,1,n,x,v); } }