比赛 |
20110723 |
评测结果 |
AWWWWTWE |
题目名称 |
儿童节快乐 |
最终得分 |
12 |
用户昵称 |
donny |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2011-07-23 10:08:33 |
显示代码纯文本
program happya;
const
er:array[1..15]of longint=(2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768);
var
a,left,right,ge:array[1..32768]of longint;
i,j,k,l:longint;
c:char;
n,m:longint;
o,p,q,r:longint;
procedure increase(x,y:longint);
var
i,j:longint;
begin
inc(a[x],y);
j:=x;
i:=x div 2;
while i<>0 do
begin
if a[i]>=a[j] then break;
a[i]:=a[j];
ge[i]:=x;
j:=i;
i:=i div 2;
end;
end;
procedure find(x:longint);
begin
if (left[x]>=o)and(right[x]<=p) then
begin
if a[x]>r then
begin
r:=a[x];
q:=ge[x];
end;
end
else
begin
if o<=right[x*2] then
find(x*2);
if p>=left[x*2+1] then
find(x*2+1);
end;
end;
function max(x,y:longint):longint;
begin
if x>y then exit(x)
else exit(y);
end;
begin
assign(input,'happya.in');
reset(input);
assign(output,'happya.out');
rewrite(output);
readln(n,m);
for i:=1 to 15 do
if er[i]>n then break;
k:=i;
for i:=er[k] to er[k+1]-1 do
begin
a[i]:=0;
left[i]:=i-er[k]+1;
right[i]:=left[i];
ge[i]:=i;
end;
for i:=er[k]-1 downto 1 do
begin
a[i]:=0;
left[i]:=left[2*i];
right[i]:=right[2*i+1];
ge[i]:=0;
end;
for l:=1 to m do
begin
read(c);
case c of
'I':
begin
readln(o,p,q);
for i:=o to p do
increase(er[k]+i-1,q);
end;
'C':
begin
readln(o,p);
r:=0;
q:=0;
find(1);
writeln(r);
a[q]:=0;
i:=q div 2;
j:=q;
while i<>0 do
begin
r:=max(a[i*2],a[i*2+1]);
if r=a[i] then break;
a[i]:=r;
r:=i*2;
if r=j then
ge[i]:=ge[r+1]
else
ge[i]:=ge[r];
j:=i;
i:=i div 2;
end;
end;
end;
end;
close(input);
close(output);
end.