⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ac1126.pas

📁 uralcode
💻 PAS
字号:
program ural1126;
const
  maxm=14000;
  treesize=131071;
  root=65536;
  maxd=32768;
var
  tree:array[1..treesize]of longint;
  a:array[0..maxm-1]of longint;
  m,i:word;
  x:longint;
procedure modify(x:longint;y:shortint);
  var
    p,d:longint;
  begin
    p:=root;d:=maxd;
    while p<>x do begin
      inc(tree[p],y);
      if p<x then inc(p,d) else dec(p,d);
      d:=d shr 1;
    end;
    inc(tree[p],y);
  end;
function max:longint;
  var
    p,d:longint;
  begin
    p:=root;d:=maxd;
    repeat
      if tree[p+d]>0 then
        inc(p,d)
      else if tree[p]>tree[p-d] then
        break
      else
        dec(p,d);
      d:=d shr 1;
    until odd(p);
    max:=p;
  end;
begin
  read(m);
  repeat
    read(x);
    if x=-1 then halt;
    inc(x);inc(i);
    if i>m then modify(a[i mod m],-1);
    a[i mod m]:=x;modify(x,1);
    if i>=m then writeln(max-1);
  until false;
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -