#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug cout<<"hbgf"<<endl;
const int mod=1e4+7;
const int maxx=2e5+10;
stack<char>ss;
ll q[maxx*4],w[maxx*4];
ll a[maxx*4];
void push(int root){
q[root] = min(q[root<<1],q[root<<1|1]);
w[root] = max(w[root<<1],w[root<<1|1]);
}
void build(int root,int l,int r){
if(l==r){
q[root]=a[l];
w[root]=a[l];
return;
}
int mid=(l+r)>>1;
build(root<<1,l,mid);
build(root<<1|1,mid+1,r);
push(root);
}
void update(int root,int l,int r,int x,int val){
if(l==r){
q[root]=val;
w[root]=val;
return;
}
int mid=(l+r)>>1;
if(x<=mid) update(root<<1,l,mid,x,val);
else update(root<<1|1,mid+1,r,x,val);
push(root);
}
int querymn(int root,int l,int r,int x,int y){
if(x<=l&&y>=r){
return q[root];
}
int minn=0x3f3f3f3f;
int mid=(l+r)>>1;
if(x<=mid) minn = min(minn, querymn(root<< 1, l, mid, x, y));
if (y>mid) minn = min(minn, querymn(root<< 1 | 1, mid + 1, r, x, y));
return minn;
}
int querymx(int root,int l,int r,int x,int y){
if(x<=l&&y>=r){
return w[root];
}
int max1=-1;
int mid=(l+r)>>1;
if(x<=mid) max1 = max(max1, querymx(root<< 1, l, mid, x, y));
if(y>mid) max1 = max(max1, querymx(root<< 1 | 1, mid + 1, r, x, y));
return max1;
}
int main(){
int n,t;
cin>>n>>t;
for(int i=1;i<=n;i++) cin>>a[i];
build(1,1,n);
while(t--){
int c,x,y;
cin>>c>>x>>y;
if(c==1){
update(1,1,n,x,y);
}
else{
int l,r;
l=querymn(1,1,n,x,y);
r=querymx(1,1,n,x,y);
// cout<<r-l<<" "<<y-x<<endl;
if(r-l==y-x) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}
return 0;
}
线段树单点修改求区间最值
最新推荐文章于 2021-08-07 15:37:58 发布