## lambda QAQ

fmap :: (q -> a) -> f q -> f a

# Spoj 1716 Can you answer these queries III

（几乎一样的题和几乎一样的代码

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int maxn = 112345;

#define LL long long
const LL INFF = 0x3f3f3f3f3f3f3f3fll;

struct Info{
LL lmax,rmax,sum,val;
void maintain(LL x){
lmax=rmax=sum=val=x;
}
Info(){
maintain(-INFF);
sum=0;
}
};

Info operator + (const Info & a,const Info & b){
Info ret;
ret.sum=a.sum+b.sum;
ret.lmax=max(a.lmax,a.sum+b.lmax);
ret.rmax=max(b.rmax,b.sum+a.rmax);
ret.val=max(max(a.val,b.val),a.rmax+b.lmax);
return ret;
}

#define lson o<<1,l,m
#define rson o<<1|1,m+1,r
#define root 1,1,n
#define Now int o,int l,int r
#define Mid int m = l + (r-l)/2

Info sarr[maxn*4];

void update(Now,int p,LL v){
if(l==r){
sarr[o].maintain(v);
return;
}
Mid;
if(p<=m) update(lson,p,v);
else update(rson,p,v);
sarr[o]=sarr[o<<1]+sarr[o<<1|1];
}

Info query(Now,int ql,int qr){
if(ql<=l && r<=qr){
return sarr[o];
}
Mid;
Info ret;
if(ql<=m) ret = query(lson,ql,qr) + ret;
if(m+1<=qr) ret = ret + query(rson,ql,qr);
return ret;
}

int main(){
int n;
while(~scanf("%d",&n)){
LL x;
for(int i=1;i<=n;i++){
scanf("%lld",&x);
update(root,i,x);
}
int m;
scanf("%d",&m);
int l,r,p,ord;
while(m--){
scanf("%d",&ord);
if(ord==1){
scanf("%d %d",&l,&r);
printf("%lld\n",query(root,l,r).val);
}
else{
scanf("%d %lld",&p,&x);
update(root,p,x);
}
}
}
return 0;
}



#### SPOJ GSS2 Can you answer these queries II

2015-04-09 19:00:08

#### SPOJ GSS3: Can you answer these queries III 题解

2018-03-19 20:21:51

#### SPOJ 4487. Can you answer these queries VI（GSS6 Splay tree）

2012-09-17 20:58:59

#### 【SPOJ-GSS6】Can you answer these queries VI【Splay】

2016-02-19 21:15:58

#### SPOJ GSS4 Can you answer these queries IV (线段树)

2014-05-17 17:09:33

#### SPOJ GSS5 Can you answer these queries V （线段树）

2014-05-18 00:09:34

#### [SPOJ GSS2] Can you answer these queries II [线段树]

2014-07-27 10:31:01

#### SPOJ GSS6 4487. Can you answer these queries VI (SPLAY)

2014-07-27 10:59:48

#### 【SPOJ】4487 Can you answer these queries VI 【splay】

2014-09-17 16:09:20

#### SPOJ GSS6: Can you answer these queries VI 题解

2018-03-19 21:51:25