Tyvj 1607 小熊的早餐

题目:

 小熊的早餐

来源:

 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值