###### HDU 1754

Description

Input

import java.util.Scanner;

public class ProbelmB {

private static final int MAX_NUM = 1000000;
private static int[] tree  = new int[MAX_NUM];
private static  Scanner scaner ;
public static void main(String[] args) {
scaner = new Scanner(System.in);
while(scaner.hasNext()) {
int num = scaner.nextInt();
int number = scaner.nextInt();
buildTree(1,num,1);
while(number-- !=0) {
String flag = scaner.next();
int a = scaner.nextInt();
int b = scaner.nextInt();
if (flag.equals("Q")) {
System.out.println(query(a,b,1,num,1));
}else{
updata(a,b,1,num,1);
}
}

}
scaner.close();
}
/*
构建线段树
*/
private static void buildTree(int left,int right,int root) {
if(left == right) {
tree[root] = scaner.nextInt();
return ;
}else{
int mid = (left+right) >> 1;
buildTree(left,mid,root<<1); //左边递归
buildTree(mid + 1,right,root << 1 | 1);
tree[root] = Math.max(tree[root<<1],tree[root<<1 | 1]); //在两个子节点中选取最大值

}

}

/*
点更新
*/
private static void updata(int point,int value,int left,int right,int root) {
if (left == right) {
tree[root] = value; //当left == right 时 将值赋给对应点，然后回溯更新节点的值
return ;
}else{
int mid = (left + right) >> 1;
if (point <= mid) {
updata(point,value,left,mid,root <<1);
}else{
updata(point,value,mid+1,right,root << 1 | 1);
}
tree[root] = Math.max(tree[root<<1],tree[root<<1 | 1]);
}
}
/*
查询区间的最大值
*/
private static  int query(int L,int R,int left,int right,int root) {
if (L <= left && right <= R) {
return tree[root];
}else{
int sum = 0,mid = (left +right)>>1;

if (L <= mid ) { //在两边找最大值，
sum = Math.max(sum,query(L,R,left,mid,root << 1 ));

}
if (R > mid) {
sum = Math.max(sum,query(L,R,mid+1,right,root<<1 |1));
}
return sum;
}

}
}

#### 杭电 hdu 1754 I Hate It （线段树 + 详细注释）

2011-09-14 22:23:01

#### hdu1754 I hate it （线段树）

2015-12-11 11:10:53

#### HDU 1754 树状数组 解法

2014-06-06 20:47:42

#### hdu-1754 I Hate It（线段树求区间最大值）

2016-03-15 13:14:12

#### 杭电 HDU ACM 1754 I Hate It （线段树）

2015-07-01 10:13:05

#### [HDU 1754]I Hate It[树状数组查询+更新区间最大值]

2015-09-15 17:22:14

#### HDU 1166 单点更新 区间求和（ZKW 线段树）

2016-09-11 10:02:46

#### 【hdu1754】树状数组 区间最值

2016-10-19 08:47:24

#### hdu 1754 I Hate It （线段树）

2013-12-06 21:01:17

#### HDU1754 I Hate It (线段树java版)

2014-03-03 11:57:43

HDU 1754