这几天都在琢磨动态规划的单调性优化了,必然会用到很多队列的操作
所以先搞一道队列的模拟水题
主要还是想试试高亮代码效果怎么样。。。
这个代码还是之前用pascal写的。虽然写的很随意,但是时间空间,尤其是代码长度都都排在前面。
//By YY_More type que=record data,pos:longint end; var n,l,r,m,k,h:longint; s:string; d:array[0..1000000]of que; begin readln(n); while n>0 do begin readln(s); if s[1]='E' then dec(n); if s[1]='S' then begin l:=1;r:=0;m:=0;k:=0; end; if s[1]='G' then begin inc(m); if d[l].pos<=m then inc(l); end; if s[1]='Q' then if l>r then writeln(-1) else writeln(d[l].data); if s[1]='C' then begin inc(k); delete(s,1,pos(' ',s)); delete(s,1,pos(' ',s)); val(s,h); while (d[r].data<h)and(r>=l) do dec(r); inc(r); d[r].data:=h;d[r].pos:=k; end; end; end.