题目
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.