hdu1753I Hate It(线段树)
来源:互联网 发布:全局优化的方法有哪些 编辑:程序博客网 时间:2024/05/21 14:41
http://acm.hdu.edu.cn/showproblem.php?pid=1754
单点更新,区间求最值
// File Name: hdu1754.cpp// Author: bo_jwolf// Created Time: 2013年08月16日 星期五 11点27分03秒#include<vector>#include<list>#include<map>#include<set>#include<deque>#include<stack>#include<bitset>#include<algorithm>#include<functional>#include<numeric>#include<utility>#include<sstream>#include<iostream>#include<iomanip>#include<cstdio>#include<cmath>#include<cstdlib>#include<cstring>#include<ctime>using namespace std;#define lson l , mid , rt << 1 #define rson mid + 1 , r , rt << 1 | 1 const int maxn = 200005 ;//int sum[ maxn << 2 ] ;struct node{int Max ;}tree[ maxn << 2 ] ;void PushUp( int rt ){tree[ rt ].Max = max( tree[ rt << 1 ].Max , tree[ (rt << 1 | 1 ) ].Max ) ;}void build( int l , int r , int rt ){if( l == r ){scanf( "%d" , &tree[ rt ].Max );return ;}int mid = ( l + r ) >> 1 ;build( lson ) ;build( rson ) ;PushUp( rt ) ;}void update( int p , int add , int l , int r , int rt ){if( l == r ){tree[ rt ].Max = add ;return ;}int mid = ( l + r ) >> 1 ;if( p <= mid )update( p , add , lson ) ;elseupdate( p , add , rson ) ;PushUp( rt ) ;}int query( int L , int R , int l , int r , int rt ){if( L <= l && r <=R ){return tree[ rt ].Max ;}int mid = ( l + r ) >> 1 ;int ret = 0 ; if( L <= mid )ret = max( ret , query( L , R , lson ) ) ;if( R > mid )ret = max( ret , query( L , R , rson ) );return ret ;}int main(){int T , n , m ; while( scanf( "%d%d" , &n , &m ) != EOF ){build( 1 , n , 1 ) ;char op[ 10 ] ;while( m-- ){scanf( "%s" , op ) ;int a , b ;scanf( "%d%d" , &a , &b ) ;if( op[ 0 ] == 'Q' )printf( "%d\n" , query( a , b , 1 , n , 1 ) ) ;elseupdate( a , b , 1 , n , 1 ) ;}}return 0;}
- hdu1753I Hate It(线段树)
- HDU I hate it(线段树)
- hdu1754___I Hate It (线段树)
- I Hate It(线段树)
- I Hate It(线段树)
- I Hate It(线段树)
- I hate it (线段树)
- 线段树(hdu1754 I hate it)
- HDU_1754 I Hate It(线段树)
- hdu1754-I Hate It(线段树)
- hdu1754 I hate it (线段树)
- P1531 I Hate It(线段树)
- HDU1754:I Hate It(线段树)
- hdu1754 I Hate It (线段树)
- I Hate It (线段树)
- 【HDU1754】I Hate It(线段树)
- 【HDU1754-I hate it】(线段树)
- I Hate It(基本线段树)
- android 解析json数据格式
- hdu1166-敌兵布阵(线段树)
- Ubuntu12.04 配置Goagent
- HDU 4681 String(DP 最长公共子系列)
- How to Write Doc Comments for the Javadoc Tool
- hdu1753I Hate It(线段树)
- 130+ essential vim commands
- Codeforces Round #178 (Div. 2) / 294A Shaass and Oskols(模拟)
- 如何查看Linux系统中逻辑和物理cpu的个数
- [LeetCode] Longest Substring Without Repeating Characters
- uva 11542 Square 高斯消元变形+异或消元
- firefox 快捷键
- 微信公众平台开发[2]-开发模式-接收消息
- 在drupal7中动态的为某个内容类型添加字段