[hdu1754]I Hate It

传送门

http://acm.hdu.edu.cn/showproblem.php?pid=1754

题目大意

单点修改+区间查询最大值

题解

注意有多组数据

var
 w:array[0..800005,1..3]of longint;
 i,j,k:longint;
 n,m:longint;
 ch:char;
 a,b:longint;
function max(a,b:longint):longint;
begin
 if a>b then exit(a) else exit(b);
end;

procedure build(a,l,r:longint);
var mid:longint;
begin
 w[a,1]:=l; w[a,2]:=r;
 if l=r then begin read(w[a,3]); exit; end;
 mid:=(l+r)>>1;
 build(a<<1,l,mid); build(a<<1+1,mid+1,r);
 w[a,3]:=max(w[a<<1,3],w[a<<1+1,3]);
end;

procedure update(a,b,c:longint);
var mid:longint;
begin
 if (w[a,1]=w[a,2])and(w[a,1]=b) then begin w[a,3]:=c; exit; end;
 mid:=(w[a,1]+w[a,2])>>1;
 if b<=mid then update(a<<1,b,c) else update(a<<1+1,b,c);
 w[a,3]:=max(w[a<<1,3],w[a<<1+1,3]);
end;

function query(a,l,r:longint):longint;
var mid:longint;
begin
 if (w[a,1]=l)and(w[a,2]=r) then exit(w[a,3]);
 mid:=(w[a,1]+w[a,2])>>1;
 if r<=mid then exit(query(a<<1,l,r)) else
 if l>mid then exit(query(a<<1+1,l,r))
 else exit(max(query(a<<1,l,mid),query(a<<1+1,mid+1,r)));
end;

begin
 while not eof do begin
 readln(n,m);
 build(1,1,n); readln;
 for i:=1 to m do
  begin
   readln(ch,a,b);
   if ch='U' then update(1,a,b);
   if ch='Q' then writeln(query(1,a,b));
  end;
 end;
end.

你可能感兴趣的:([hdu1754]I Hate It)