chen_zhe @ 2018-05-02 21:29:11
#include <iostream>
#include <algorithm>
using namespace std;
struct node
{
int value;
int left,right;
}son[2200000];
int father[2200000],n,m,Max;
void build(int id,int left,int right)
{
son[id].left=left,son[id].right=right;
if (left==right)
{
father[left]=id;
return;
}
build(id<<1,left,(left+right)>>1);
build((id<<1)+1,((left+right)>>1)+1,right);
}
void update_single(int r)
{
if (r==1) return;
int r1=r/2;
int a=son[r1<<1].value;
int b=son[(r1<<1)+1].value;
son[r1].value=a>b?a:b;
update_single(r>>1);
}
void query(int id,int left,int right)
{
if (son[id].left>=left && son[id].right<=right)
{
Max=Max>son[id].value?Max:son[id].value;
return;
}
id=id<<1;
if (left<=son[id].right)
{
if (right<=son[id].right)
query(id,left,right);
else query(id,left,son[id].right);
}
id++;
if (right>=son[id].left)
{
if (left>=son[id].left)
query(id,left,right);
else query(id,son[id].left,right);
}
}
int main()
{
//ios_base::sync_with_stdio(0);
cin >> n >> m;
build(1,1,n);
for (int i=1;i<=n;i++)
{
int a;
cin >> a;
son[father[i]].value=a;
update_single(father[i]);
}
for (int i=1;i<=m;i++)
{
int k,a,b;
cin >> k;
if (k==1)
{
Max=-1<<30;
cin >> a >> b;
if (a>b)
{
int t=a;
a=b;
b=t;
}
query(1,a,b);
cout << Max << endl;
}
else
{
cin >> a >> b;
son[father[a]].value=b;
update_single(father[a]);
}
}
return 0;
}
by Randyhoads @ 2018-05-02 21:31:10
chen_zhe没A的题,就是数据有问题
by chen_zhe @ 2018-05-02 21:36:21
@WLZS 不是啊,vijos上也是莫名WA,但是查不出错误
by 长河落日 @ 2018-05-02 21:37:11
所以就TMD置顶了?
by newbie314159 @ 2018-05-02 21:37:47
chen_zhe 又切大火题啦
by chen_zhe @ 2018-05-02 21:38:51
@长河落日 没有啊
by chen_zhe @ 2018-05-02 21:39:12
@i7_8700k 这个题不算大火题啊,vijos上难度7
by Refun @ 2018-05-02 21:39:48
@长河落日 兄弟眼科了解一下【逃
by Randyhoads @ 2018-05-02 21:40:39
@chen_zhe 线段树单点修改,求区间最大子段和?是不是讨论的时候有问题呀。。。(蒟蒻我全是乱说的)
by Wolfycz @ 2018-05-02 21:43:23
单点修改的时候是不是要把left和right也改掉啊。
by Randyhoads @ 2018-05-02 21:47:16
@chen_zhe 每个结点需要维护最大子段和,包含从左端点的最大子段和,包含右端点的最大子段和,然后讨论吧。。。