jins3599 @ 2019-11-03 15:23:55
rt
#include <bits/stdc++.h>
#define ls(x) x << 1
#define rs(x) x << 1|1
#define inf 0x3f3f3f3f
using namespace std;
const int N = 5e5 + 10;
int n , m , a[N];
struct Seg {
int l , r , len;
int lft , rgt , mid , dis;
}t[N << 2];
void pushup(int x) {
t[x].dis = t[ls(x)].dis + t[rs(x)].dis;
t[x].lft = max(t[ls(x)].lft , t[ls(x)].dis + t[rs(x)].lft);
t[x].rgt = max(t[rs(x)].rgt , t[rs(x)].dis + t[ls(x)].rgt);
t[x].mid = max(t[ls(x)].mid , t[rs(x)].mid);
t[x].mid = max(t[x].mid , t[ls(x)].rgt + t[rs(x)].lft);
}
void built(int x , int l ,int r ) {
t[x].l = l , t[x].r = r;
t[x].len = r - l + 1;
if(l == r) {
t[x].lft = t[x].rgt = t[x].mid = t[x].dis = a[l]; return;
}
int mid = (l + r )>> 1;
built(ls(x) , l , mid);
built(rs(x) , mid + 1 , r);
pushup(x);
}
Seg query(int x , int l , int r ) {
if(t[x].l >= l && t[x].r <= r) return t[x];
int mid = (t[x].l + t[x].r) >> 1;
Seg ans , lson , rson;
lson.dis = lson.mid = lson.lft = lson.rgt = -inf;
rson.dis = rson.mid = rson.lft = rson.rgt = -inf;
if(l <= mid) lson = query(ls(x) , l , r);
if(r > mid ) rson = query(rs(x) , l , r);
ans.lft = max(lson.lft , rson.lft + lson.dis);
ans.rgt = max(rson.rgt , lson.rgt + rson.dis);
ans.mid = max(lson.mid , rson.mid);
ans.mid = max(ans.mid , lson.rgt + rson.lft);
pushup(x);
return ans;
}
void updata(int x , int p , int w) {
if(t[x].l == t[x].r) {
t[x].lft = t[x].rgt = t[x].mid = t[x].dis = w; return;
}
int mid = (t[x].l + t[x].r) >> 1;
if(p <= mid) updata(ls(x) , p , w);
else updata(rs(x) , p , w);
pushup(x);
}
int main () {
//freopen("data.txt" , "r" , stdin);
//freopen("ans1.out" , "w" , stdout);
scanf("%d %d" , &n, &m);
for(int i = 1 ; i <= n ; ++ i) scanf("%d" , a + i);
built(1 ,1 ,n);
while( m --) {
int opt , l , r;
scanf("%d %d %d" , &opt , &l , &r);
if(opt == 1) {
if(l > r) swap(l , r);
Seg rans = query(1 , l , r);
printf("%d\n" , rans.mid);
} else {
updata(1 , l , r);
}
}
return 0;
}
by RinkaSnow @ 2019-11-03 15:26:11
你菜
by lccc233 @ 2019-11-03 15:26:30
@jins3599 那您可太秀了
by jins3599 @ 2019-11-03 15:26:47
@tzxydby %%%大佬
by gaeblog @ 2019-11-03 15:27:33
@tzxydby %%%大佬
by King_Parliament @ 2019-11-03 15:27:35
@tzxydby %%%大佬
by lccc233 @ 2019-11-03 15:27:37
@tzxydby %%%
by long_long @ 2019-11-03 15:28:25
666
by bit_ @ 2019-11-03 15:28:32
@tzxydby %%%神仙tql
by bit_ @ 2019-11-03 15:29:29
@jins3599 1.确定调试用的输出都删掉了
2.再换个题解对拍试试
3.确定不是对拍用的程序挂了
by wksy_ @ 2019-11-03 15:29:29
@tzxydby %%%大佬