题目说的取最小值,然后你的```query```里面用 ```max```是什么意思
by hgckythgcfhk @ 2024-04-25 09:52:48
```cpp
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
long long w[N<<2],a[N],n,m,lzy[N<<2];
void pushup(int u){
w[u]=min(w[2*u],w[2*u+1]);
}
void build(int u,int L,int R){
if(L==R){
w[u]=a[L];
return ;
}
int mid=(L+R)/2;
build(2*u,L,mid);
build(2*u+1,mid+1,R);
pushup(u);
}
void update1(int u,int L,int R,int p,int x){
if(L==R){
w[u]+=x;
return ;
}
int mid=(L+R)/2;
if(p<=mid) update1(2*u,L,mid,p,x);
else update1(2*u+1,mid+1,R,p,x);
pushup(u);
}
bool inRange(int L,int R,int l,int r){
return l<=L && R<=r;
}
bool outofRange(int L,int R,int l,int r){
return r<L || R<l;
}
void maketag(int u,int L,int R,long long x){
lzy[u]+=x;
w[u]+=x;
}
void pushdown(int u,int L,int R){
int mid=(L+R)/2;
maketag(2*u,L,mid,lzy[u]);
maketag(2*u+1,mid+1,R,lzy[u]);
lzy[u]=0;
}
void update(int u,int L,int R,int l,int r,long long x){
if(inRange(L,R,l,r)){
maketag(u,L,R,x);
}else if(!outofRange(L,R,l,r)){
int mid=(L+R)/2;
pushdown(u,L,R);
update(2*u,L,mid,l,r,x);
update(2*u+1,mid+1,R,l,r,x);
pushup(u);
}
}
long long query(int u,int L,int R,int l,int r){
if(inRange(L,R,l,r)){
return w[u];
}else if(outofRange(L,R,l,r)){
return 0;
}else{
int mid=(L+R)/2;
pushdown(u,L,R);
return min(query(2*u,L,mid,l,r),query(2*u+1,mid+1,R,l,r));
}
}
int main(){
int op,x,y,k=1;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
}
build(1,1,n);
while(m--){
cin>>op>>x>>y;
if(op==1){
update(1,1,n,x,y,k);
}else{
cout<<query(1,1,n,x,y)<<endl;
}
}
return 0;
}
```
by smile_jyc @ 2024-04-25 21:52:20
@[smile_jyc](/user/1246532) P1253
by WydnksqhbD_3 @ 2024-04-26 19:37:58