题目大意:中文
代码:
/*
* Problem ID : HDU 1754 I Hate It
* Author : Lirx.t.Una
* Language : C
* Run Time : 781 ms
* Run Memory : 2548 KB
*/
#include <memory.h>
#include <stdio.h>
#define MAXN 200000
#define LFT(T) ( (T) << 1 )
#define RHT(T) ( LFT(T) | 1 )
int seg[MAXN * 3];
int
max( int a, int b ) {
return a > b ? a : b;
}
void
update( int tree, int i, int v, int lft, int rht ) {
int mid;
if ( lft == rht ) {
seg[tree] = v;
return ;
}
seg[tree] = max( seg[tree], v );
mid = ( lft + rht ) >> 1;
if ( i <= mid ) update( LFT(tree), i, v, lft, mid );
else update( RHT(tree), i, v, mid + 1, rht );
}
int
query( int tree, int ql, int qr, int lft, int rht ) {
int mid;
if ( lft == ql && qr == rht ) return seg[tree];
mid = ( lft + rht ) >> 1;
if ( qr <= mid ) return query( LFT(tree), ql, qr, lft, mid );
else if ( ql > mid ) return query( RHT(tree), ql, qr, mid + 1, rht );
else return max( query( LFT(tree), ql, mid, lft, mid ),
query( RHT(tree), mid + 1, qr, mid + 1, rht ) );
}
int
main() {
int n, m;
int i, j;
int s;
char cmd;
while ( ~scanf("%d%d", &n, &m) ) {
memset(seg, 0, sizeof(seg));
for ( i = 1; i <= n; i++ ) {
scanf("%d", &s);
update( 1, i, s, 1, n );
}
while ( m-- ) {
scanf("\n%c%d%d", &cmd, &i, &j);
switch (cmd) {
case 'Q' :
printf("%d\n", query( 1, i, j, 1, n ));
break;
case 'U' :
update( 1, i, j, 1, n );
break;
default : break;
}
}
}
return 0;
}