比赛 20110723 评测结果 AWWWWWWW
题目名称 儿童节快乐 最终得分 12
用户昵称 Yoghurt 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2011-07-23 11:41:54
显示代码纯文本
{
Problem:
Arithmetic Analysis:
Writer:
Data:
Remark:
AC:
}
program happya;
const
        filename='happya';
        maxn=120000;
        oo=1000000000;
type
        xx=record
                key,delta,num:longint;
        end;
var
        a:array[0..maxn*4] of xx;
        n,m,x,y,add:longint;

function max(a,b:longint):longint;
begin
        if a>b then exit(a)
                else exit(b);
end;

procedure updata(left,right,root:longint);
var
        mid:longint;
begin
        if (y<left) or (x>right) then exit;
        if (x<=left) and (right<=y) then
        begin
                inc(a[root].key,add);
                inc(a[root].delta,add);
                a[root].num:=x;
                exit;
        end;
        mid:=(left+right) div 2;
        inc(a[root*2+1].key,a[root].delta);
        inc(a[root*2+1].delta,a[root].delta);
        inc(a[root*2].key,a[root].delta);
        inc(a[root*2].delta,a[root].delta);
        a[root].delta:=0;
        updata(left,mid,root*2);
        updata(mid+1,right,root*2+1);
        a[root].key:=max(a[root*2].key,a[root*2+1].key);
end;

function search(left,right,root:longint):longint;
var
        mid,m1,m2:longint;
begin
        if (y<left) or (x>right) then exit(0);
        if (x<=left) and (right<=y) then exit(root);
        mid:=(left+right) div 2;
        inc(a[root*2].key,a[root].delta);
        inc(a[root*2].delta,a[root].delta);
        inc(a[root*2+1].key,a[root].delta);
        inc(a[root*2+1].delta,a[root].delta);
        m1:=search(left,mid,root*2);
        m2:=search(mid+1,right,root*2+1);
        a[root].delta:=0;
        if (a[m1].key>a[m2].key) or ((a[m1].key=a[m2].key)and(a[m1].num<a[m2].num)) then
                exit(m1)
        else
                exit(m2);
end;

procedure solve;
var
        i,temp:longint;
        ch:char;
begin
        readln(n,m);
        fillchar(a,sizeof(a),0);
        for i:=1 to n do
        begin
                x:=i; y:=i; add:=0;
                updata(1,n,1);
        end;
        for i:=1 to m do
        begin
                read(ch);
                if ch='I' then
                begin
                        readln(x,y,add);
                        updata(1,n,1);
                end else
                begin
                        readln(x,y);
                        temp:=search(1,n,1);
                        writeln(a[temp].key);
                        add:=-a[temp].key;
                        x:=a[temp].num; y:=a[temp].num;
                        updata(1,n,1);
                end;
        end;
end;

begin
        assign(input,filename+'.in'); reset(input);
        assign(output,filename+'.out'); rewrite(output);

        solve;

        close(input); close(output);
end.