[HDU][1754][线段树] I Hate It

题目大意:

给定一个序列和两种操作:

Q操作,表示这是一条询问操作,询问区间[a,b]当中的元素的最大值是多少。

U操作,表示这是一条更新操作,要求把元素A的值更改为B。

思路:

线段树模板题。

代码:

#include
#include
using namespace std;
#define MAXSIZE 200000
int val[MAXSIZE+1];
struct node
{
    int max;
    int left;
    int right;
}tree[MAXSIZE*3];
int max(int x,int y)
{
    return x>y?x:y;
}
int create(int root,int left,int right)
//以root为根节点建树。 
{
    tree[root].left=left;
    tree[root].right=right;
    if(left==right)
        return tree[root].max=val[left];
    int a,b,middle=(left+right)/2;
    a=create(2*root,left,middle);
    b=create(2*root+1,middle+1,right);
    return tree[root].max=max(a,b);
}
int calculate(int root,int left,int right)
//以root为根节点的线段树中,求取区间[left,right]中的最大值。 
{
    if(tree[root].left>right||tree[root].right	

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注