- 小白逛公园
- 2017-07-08 23:39:16 @
#include <cstdio>
#include <iostream>
#include <algorithm>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
struct node{
int prefix, suffix, sum, sub;
}d[2000001+10];
int read(){
int x, f = 1;
char ch;
while(ch = getchar(), ch<'0'||ch>'9') if(ch =='-') f = -1;
x = ch - 48;
while(ch = getchar(),'0'<=ch&&ch<='9') x = x*10+ch-48;
return x*f;
}
void Pushup(int rt){
d[rt].sum = d[rt<<1].sum + d[rt<<1|1].sum;
d[rt].prefix = max(d[rt<<1].prefix, d[rt<<1].sum + d[rt<<1|1].prefix);
d[rt].suffix = max(d[rt<<1|1].suffix, d[rt<<1|1].sum + d[rt<<1].suffix);
d[rt].sub = max(d[rt<<1].sub, max(d[rt<<1|1].sub, d[rt<<1].suffix+d[rt<<1|1].prefix));
}
void build(int l, int r, int rt){
if(l == r){
d[rt].prefix = d[rt].suffix = d[rt].sum = d[rt].sub = read();
return;
}
int m = l+r>>1;
build(lson);
build(rson);
Pushup(rt);
}
void update(int l, int r, int rt, int p, int s){
if(l == r){
d[rt].prefix = d[rt].suffix = d[rt].sum = d[rt].sub = s;
return;
}
int m = l+r>>1;
if(p <= m) update(lson, p, s);
else update(rson, p, s);
Pushup(rt);
}
node query(int l, int r, int rt, int a, int b){
if(l >= a && r <= b) return d[rt];
int m = l+r>>1;
if(b <= m) return query(lson, a, b);
else if(a > m) return query(rson, a, b);
else{
node ans1, ans2, ans3;
ans1 = query(lson, a, m);
ans2 = query(rson, m+1, b);
ans3.sum = ans1.sum + ans2.sum;
ans3.prefix = max(ans1.prefix, ans1.sum+ans2.suffix);
ans3.suffix = max(ans2.suffix, ans1.suffix+ans2.sum);
ans3.sub = max(ans1.sub, max(ans2.sub, ans1.suffix+ans2.prefix));
return ans3;
}
}
int main(){
int i, j, n, mm, o, a, b, t;
n = read(); mm = read();
build(1,n,1);
for(i = 1; i <= mm; i++){
o = read(); a = read(); b = read();
if(o == 1){
if(a > b) swap(a,b);
printf("%d\n", query(1,n,1,a,b).sub);
}
else update(1,n,1,a,b);
}
return 0;
}
4 条评论
-
zyc2000 LV 9 @ 2018-03-09 10:32:33
状态 题目 递交者 时间 内存 语言 递交时间 Accepted P1083 小白逛公园 zyc2000 1315ms 30.848 MiB C++ 2分钟前 Wrong Answer P1083 小白逛公园 zyc2000 1159ms 30.844 MiB C++ 8分钟前 Wrong Answer P1083 小白逛公园 zyc2000 1033ms 30.832 MiB C++ 26分钟前
a可以大于b!
就这个条件, 不注意会全部WA!
(严重怀疑这道题的AC率就是这样被拉低的...题目本来没这么难) -
2017-07-09 00:11:31@
我自己根本找不到错啊QAQ
-
2017-07-09 00:09:09@
贼烦!!!!!!!
-
2017-07-09 00:08:54@
啊啊啊啊啊啊交了好多次都是错
- 1