| 题目: | 小熊的早餐 | |
| 来源: | Tyvj 1607 | |
| 题目大意: | N个数M次操作,查询最大值、修改值、修改为-无穷,起初N个数为0 | |
| 数据范围: | 0<n,m<=100000 | |
| 样例: | 10 6 Yummy Like 5 100 Yummy Like 6 99 Unlike 5 Yummy | 0 100 99 |
| 做题思路: | Andy的生日赛,所以祝andy生日快乐,迟到的祝福也要+rp。。 这题和忠诚2差不多,rmq问题,输出根,插入值 | |
| 知识点: | Rmq、线段树 | |
const MaxN=100010;
type
tre=record
l,r,lc,rc,max:longint;
end;//tre
var
tree:array[0..MaxN*4] of tre;
n,m,i,j,x,a,b,root,tot,ans,p:longint;
ch:char;
s:string;
procedure build(var t:longint;l,r:longint);
begin
inc(tot);t:=tot;
tree[t].l:=l;tree[t].r:=r;
tree[t].max:=0;
ifl<r then
begin
build(tree[t].lc,l,(l+r)div 2);
build(tree[t].rc,(l+r)div 2+1,r);
end;//if
end;
function max(a,b:longint):longint;
begin
ifa<b then exit(b);
exit(a);
end;
procedure insert(t,i:longint);
begin
ift=0 then exit;
iftree[t].l=tree[t].r then
begin
tree[t].max:=x;
exit;
end;
iftree[tree[t].lc].r>=i then insert(tree[t].lc,i)
else insert(tree[t].rc,i);
tree[t].max:=max(tree[tree[t].lc].max,tree[tree[t].rc].max);{<边插入边维护>}
end;
begin
readln(n,m);
root:=0;tot:=0;
build(root,1,n);
fori:=1 to m do
begin
read(ch);
case ch of
'Y':begin
writeln(tree[root].max);
readln(s);
end;
'L':begin
while ch<>' ' do read(ch);
readln(a,x);
insert(root,a);
end;
'U':begin{<不喜欢就是插入-maxlongint>}
while ch<>' ' do read(ch);
readln(a);
x:=-maxlongint;
insert(root,a);
end;
end;
end;
end.题目来源:
http://www.tyvj.cn:8080/Problem_Show.asp?id=1607


113

被折叠的 条评论
为什么被折叠?



