比赛 |
20110723 |
评测结果 |
AWWWWTWT |
题目名称 |
儿童节快乐 |
最终得分 |
12 |
用户昵称 |
WSJZX |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2011-07-23 12:48:44 |
显示代码纯文本
program happya;
type
arry=record
key,num:longint;
end;
var
i,j,n,t,total,ans,x,y,w,m,v:longint;
tree:array[0..100000*5] of arry;
ch:char;
procedure change(x,l,r,p,v:longint);
var
m:longint;
begin
if (l>p)or(r<p) then exit;
if l=r then
begin
tree[x].key:=tree[x].key+v;
tree[x].num:=j;
exit;
end;
m:=(l+r) div 2;
if p<=m then change(x+x,l,m,p,v);
if p>m then change(x+x+1,m+1,r,p,v);
if tree[2*x].key>=tree[2*x+1].key then
begin
if tree[x].key<tree[2*x].key then
tree[x]:=tree[2*x];
end
else
if tree[x].key<tree[2*x+1].key then
tree[x]:=tree[2*x+1];
end;
function query(root,l,r:longint):longint;
var
m1,m2,m:longint;
begin
if (r<x)or(l>y) then exit(0);
if (l>=x)and(r<=y) then exit(root);
m:=(l+r) div 2;
m1:=query(root*2,l,m);
m2:=query(root*2+1,m+1,r);
if tree[m1].key>=tree[m2].key then exit(m1)
else exit(m2);
end;
procedure change1(x,l,r,p,v:longint);
var
m:longint;
begin
if (l>p)or(r<p) then exit;
if l=r then
begin
tree[x].key:=v;
exit;
end;
m:=(l+r) div 2;
if p<=m then change1(x+x,l,m,p,v);
if p>m then change1(x+x+1,m+1,r,p,v);
if tree[2*x].key>=tree[2*x+1].key then
tree[x]:=tree[2*x]
else
tree[x]:=tree[2*x+1];
end;
begin
assign(input,'happya.in');reset(input);
assign(output,'happya.out');rewrite(output);
fillchar(tree,sizeof(tree),0);
readln(n,m);
for i:=1 to m do
begin
read(ch);
if ch='I' then
begin
readln(x,y,v);
for j:=x to y do
change(1,1,n,j,v)
end
else
begin
readln(x,y);
t:=tree[query(1,1,n)].num;
writeln(tree[query(1,1,n)].key);
change1(1,1,n,t,0);
end;
end;
close(input);close(output);
end.