兮水XiShui丶 @ 2019-01-28 21:00:19
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
template < class T >
inline void read ( T &x ) {
int s = 0 , w = 1;
char ch = getchar ();
while ( ch > '9' || ch < '0' ) { if ( ch == '-' ) w = -1; ch = getchar ();}
while ( ch >= '0' && ch <= '9' ) { s = s * 10 + ch - '0'; ch = getchar ();}
x = s * w;
return;
}
template < typename T , typename ...Argc >
inline void read ( T &x , Argc &...argc ) {
read ( x );
read ( argc... );
return;
}
const int INF = 998244353;
const int N = 5e5 + 10;
int n , m;
int val[N];
struct Tree {
int size;
int lmax , rmax;
int val , sum;
}tree[N << 2];
namespace Support {
inline void swap ( int x , int y ) {
int t = x;
x = y;
y = t;
}
inline int max ( int x , int y ) {
return x > y ? x : y;
}
inline int min ( int x , int y ) {
return x < y ? x : y;
}
}
using namespace Support;
#define LC ( root << 1 )
#define RC ( root << 1 | 1 )
void Build ( int root , int start , int end ) {
tree[root].size = end - start + 1;
if ( start == end ) {
tree[root].lmax = val[start];
tree[root].rmax = val[start];
tree[root].val = val[start];
tree[root].sum = val[start];
return;
}
int mid = ( start + end ) >> 1;
Build ( LC , start , mid );
Build ( RC , mid + 1 , end );
tree[root].sum = tree[LC].sum + tree[RC].sum;
tree[root].lmax = max ( tree[LC].lmax , tree[RC].lmax + tree[LC].sum );
tree[root].rmax = max ( tree[RC].rmax , tree[RC].sum + tree[LC].rmax );
tree[root].val = max ( max ( tree[RC].val , tree[LC].val ) , tree[LC].rmax + tree[RC].lmax );
return;
}
void update ( int root , int start , int end , int pos , int val ) {
if ( pos > end || pos < start )
return;
if ( start == end ) {
if ( start == pos ) {
tree[root].val = val;
tree[root].lmax = val;
tree[root].rmax = val;
tree[root].sum = val;
}
return;
}
int mid = ( start + end ) >> 1;
update ( LC , start , mid , pos , val );
update ( RC , mid + 1 , end , pos , val );
tree[root].sum = tree[LC].sum + tree[RC].sum;
tree[root].lmax = max ( tree[LC].lmax , tree[RC].lmax + tree[LC].sum );
tree[root].rmax = max ( tree[RC].rmax , tree[RC].sum + tree[LC].rmax );
tree[root].val = max ( max ( tree[RC].val , tree[LC].val ) , tree[LC].rmax + tree[RC].lmax );
return;
}
Tree check ( int root , int nstart , int nend , int qstart , int qend ) {
Tree ne;
ne.lmax = ne.rmax = ne.sum = ne.val = -INF;
if ( qstart > nend || qend < nstart ) return ne;
if ( qstart <= nstart && qend >= nend ) return tree[root];
int mid = ( nstart + nend ) >> 1;
Tree x = check ( LC , nstart , mid , qstart , qend ) , y = check ( RC , mid + 1 , nend , qstart , qend );
ne.sum = x.sum + y.sum;
ne.lmax = max ( x.lmax , y.lmax + x.sum );
ne.rmax = max ( y.rmax , x.rmax + y.sum );
ne.val = max ( max ( x.val , y.val ) , x.rmax + y.lmax );
return ne;
}
int main ( void ) {
read ( n , m );
for ( int i = 1 ; i <= n ; i++ )
read ( val[i] );
Build ( 1 , 1 , n );
for ( int i = 1 ; i <= m ; i++ ) {
int opts;
read ( opts );
if ( opts == 1 ) {
int l , r;
read ( l , r );
if ( l > r )
swap ( l ,r );
printf ( "%d\n" , check ( 1 , 1 , n , l , r ).val );
continue;
}
else if ( opts == 2 ) {
int p , s;
read ( p , s );
update ( 1 , 1 , n , p , s );
continue;
}
}
return 0;
}
by 兮水XiShui丶 @ 2019-01-29 16:29:51
@Sai_0511 找到锅了,是我手写的min,max函数的锅QAQ...
by wangyujun @ 2019-07-05 10:31:35
@Kirito_Rivaille
我 亦 相 逢 堪 笑 语
也 知 身 世 在 江 湖
是 中 若 有 神 仙 术
鸭 绿 溪 边 好 画 图