HIHO 线段树(单点)

时间:2021-11-24 19:30:14
 #include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
using namespace std;
const int MM=;//10^6
int num[MM<<];
void buildtree(int l,int r,int id)
{
if(l==r)
{scanf("%d",&num[id]);return;}
else
{
int mid=(r+l)>>;
buildtree(l,mid,id<<);
buildtree(mid+,r,id<<|);
}
num[id]=min(num[id<<],num[id<<|]); }
int query(int L,int R,int l,int r,int id)
{
int minn=0x7fffffff;
if (L <= l && r <= R) {
return num[id];
}
else {
int mid=(r+l)>>;
if(L<=mid)minn=min(minn,query(L,R,l,mid,id<<));
if(R>mid)minn=min(minn,query(L,R,mid+,r,id<<|));
num[id]=min(num[id<<], num[id<<|]);
return minn;
}
}
void change(int pos,int e,int l,int r,int id)
{
if(l==r)
{num[id]=e;return;}
else
{
int mid=(r+l)>>;
if(pos<= mid)
change(pos,e,l,mid,id<<);
else change(pos,e,mid+,r,id<<|);
}
num[id]=min(num[id<<],num[id<<|]); }
int main(){
int i,n,que,number,x,y,z;
n=;
while(n--)
{
cin>>number;
buildtree(,number,);
cin>>que;
//cout << "ok" << endl;
for(i=;i<que;i++)
{
scanf("%d%d%d",&x,&y,&z);
//cout << x << " " << y << " " << z << endl;
if(x==)
{
int ans=query(y,z,,number,);
printf("%d\n",ans );
}
else change(y,z,,number,);
} }
return ;
}