【NOIP2016提高A组模拟9.14】数列编辑器

题目

这里写图片描述
这里写图片描述
Sample Input

8
I 2
I -1
I 1
Q 3
L
D
R
Q 2
这里写图片描述
Sample Output

2
3
这里写图片描述

比赛时の想法

暴力都有90分啦然而splay才多5分QAQ

正解

发现每一次询问的位置都是在当前光标前面的,所以我们可以每一次移动光标更新一次当前节点的值就好了,因为修改/删除操作只会对当前位置的后面造成影响

贴代码

来感受一波恐惧吧,蛤!

var
    last,next,sum,a,max,c:array[0..1000005]of longint;
    i,j,k,l,n,x,la,now:longint;
    ch:char;
    bz,bz1:boolean;
begin
   // assign(input,'t3.in'); reset(input);
  //  assign(output,'t3.out'); rewrite(output);
    readln(n);
    l:=0;
    bz:=true;
    for i:=1 to n do
    begin
        //if i=79 then
        if i=199727 then
        begin
            ch:=' ';

        end;
      //  if (next[7]=9) and (last[9]=0) then writeln(ch,' ',i);
      //  if l=1 then writeln('aa',i);
        read(ch);
        last[0]:=0;
        sum[0]:=-maxlongint;
        max[0]:=-maxlongint;
        if ch='I' then
        begin
            readln(x);
            if bz=false then
            begin
                l:=last[l];
                bz:=true;
            end;
            inc(la);
            k:=next[l];
            next[l]:=la;
            last[la]:=l;
            next[la]:=k;
            last[k]:=la;
            a[la]:=x;
            inc(now);
            c[now]:=la;
            if l=0 then sum[l]:=0;
            sum[la]:=sum[l]+a[la];
            if sum[la]>max[l] then max[la]:=sum[la] else max[la]:=max[l];
            l:=la;
        end else
        if ch='D' then
        begin
            if bz=true then
            begin
                next[last[l]]:=next[l];
                last[next[l]]:=last[l];
                l:=last[l];// else bz:=false;
                if now=0 then now:=1;
                dec(now);
                c[now]:=l;
                readln;
                continue;
            end;
            sum[l]:=sum[l]-a[last[l]];
            next[last[last[l]]]:=l;
            last[l]:=last[last[l]];
            if now=0 then now:=1;
            dec(now);
            c[now]:=last[l];
            if sum[l]>max[last[l]] then max[l]:=sum[l] else max[l]:=max[last[l]];
            readln;
        end else
        if ch='L' then
        begin
            if l=0 then
            begin
                readln;
                continue;
            end;
            if bz=true then
            begin
                bz:=false;
                if now=0 then now:=1;
                dec(now);
                c[now]:=last[l];
                readln;
                continue;
            end;
            if last[l]<>0 then
            begin
                l:=last[l];
                if now=0 then now:=1;
                dec(now);
                c[now]:=last[l];
            end else
            begin
               // l:=last[l];
                bz:=false;
                if now=0 then now:=1;
                dec(now);
                c[now]:=last[l];
            end;
            readln;
        end else
        if ch='R' then
        begin
            if next[l]<>0 then
            begin
                if bz=true then l:=next[l] else bz:=true;
                if last[l]=0 then sum[0]:=0;
                sum[l]:=sum[last[l]]+a[l];
                if sum[l]>max[last[l]] then max[l]:=sum[l] else max[l]:=max[last[l]];
                inc(now);
                c[now]:=l;
            end else
            if bz=false then
            begin
                bz:=true;
                inc(now);
                c[now]:=l;
            end;
            readln;
        end else
        begin
            readln(x);
          //  if max[c[x]]<-2000000 then writeln(c[x]);
          //  continue;
         //   if max[c[x]]=826 then writeln(x);
         //   continue;
            writeln(max[c[x]]);
        end;
    end;
    //close(input); close(output);
end.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值