代码模板:
#include<cstdio>
#include<algorithm>
using namespace std;
struct Node
{
int l,r,sum,Max,Min;
}Tree[1000<<2];
void PushUp(int o)
{
Tree[o].sum = Tree[o*2].sum + Tree[o*2+1].sum;
Tree[o].Max = max(Tree[o*2].Max,Tree[o*2+1].Max);
Tree[o].Min = min(Tree[o*2].Min,Tree[o*2+1].Min);
}
void Build(int o,int l,int r)
{
//首先记录l和r的值
Tree[o].l = l;
Tree[o].r = r;
if (l == r) //到达最底层,递归终止
{
int t;
scanf ("%d",&t); //输入数据
Tree[o].sum = Tree[o].Max = Tree[o].Min = t; //更新节点数据