比赛 |
20110723 |
评测结果 |
AAWWWWWW |
题目名称 |
儿童节快乐 |
最终得分 |
25 |
用户昵称 |
ZhouHang |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2011-07-23 12:57:33 |
显示代码纯文本
Program Happya;
Const
inf = 'happya.in';
ouf = 'happya.out';
Var
a : array[0..400100,1..4] of longint;
n,m,ans,i,x,y,c,tmp,tm : longint;
ch : char;
Function Max(xx,yy : longint): longint;
Begin
if xx<yy then exit(yy);
exit(xx);
End;
Procedure Updata(left,right,root : longint);
Var
mid : longint;
Begin
a[root,4] := left;
if (y<left) or (x>right) then exit;
if (x<=left) and (y>=right) then
begin
a[root,1] := a[root,1] + c;
a[root,2] := a[root,2] + c;
exit;
end;
mid := (left+right) div 2;
inc(a[root*2,1],a[root,2]);
inc(a[root*2,2],a[root,2]);
inc(a[root*2+1,1],a[root,2]);
inc(a[root*2+1,2],a[root,2]);
a[root,2] := 0;
Updata(left,mid,root*2);
Updata(mid+1,right,root*2+1);
if a[root*2,1]>=a[root*2+1,1]
then begin
a[root,1] := a[root*2,1];
a[root,3] := a[root*2,3];
a[root,4] := a[root*2,4];
end
else begin
a[root,1] := a[root*2+1,1];
a[root,3] := a[root*2+1,3];
a[root,4] := a[root*2+1,4]
end;
End;
Function Find(left,right,root : longint): longint;
Var
m1,m2,mid,tmp1,tmp2,tm1,tm2 : longint;
Begin
if (y<left)or(x>right) then exit(-maxlongint);
if (x<=left)and(y>=right) then
begin tmp := a[root,3]; tm := a[root,4]; exit(a[root,1]); end;
mid := (left+right) div 2;
a[root*2,1]:=a[root*2,1]+a[root,2];
a[root*2,2]:=a[root*2,2]+a[root,2];
a[root*2+1,1]:=a[root*2+1,1]+a[root,2];
a[root*2+1,2]:=a[root*2+1,2]+a[root,2];
a[root,2]:=0;
m1:=find(left,mid,root*2);
tmp1 := tmp; tm1 := tm;
m2:=find(mid+1,right,root*2+1);
tmp2 := tmp; tm2 := tm;
{if m1>=m2
then begin
a[root,1] := a[root*2,1];
a[root,3] := a[root*2,3];
a[root,4] := a[root*2,4];
end
else begin
a[root,1] := a[root*2+1,1];
a[root,3] := a[root*2+1,3];
a[root,4] := a[root*2+1,4];
end;}
if m1>=m2 then begin tmp := tmp1; tm := tm1; end
else begin tmp := tmp2; tm := tm2; end;
exit(Max(m1,m2));
End;
Procedure Delete(x,left,right,root : longint);
Var
mid : longint;
Begin
if (left=right) then begin a[x,1] := 0; exit; end;
mid := (left + right) div 2;
if tm<=mid then Delete(x,left,mid,root*2)
else Delete(x,mid+1,right,root*2+1);
if a[root*2,1]>=a[root*2+1,1]
then begin
a[root,1] := a[root*2,1];
a[root,3] := a[root*2,3];
a[root,4] := a[root*2,4];
end
else begin
a[root,1] := a[root*2+1,1];
a[root,3] := a[root*2+1,3];
a[root,4] := a[root*2+1,4];
end;
End;
Begin
Assign(input,inf); Reset(input);
Assign(output,ouf); Rewrite(output);
readln(n,m);
for i := 1 to 2*n-1 do a[i,3] := i;
for i := 1 to m do
begin
read(ch);
if ch='I' then readln(x,y,c)
else readln(x,y);
if ch='I' then Updata(1,n,1)
else begin
ans := Find(1,n,1);
a[tmp,1] := 0;
Delete(tmp,1,n,1);
writeln(ans);
end;
end;
Close(input); Close(output);
End.