比赛 NOI2015Day1 评测结果 WWEEEEEEEEEEEEEEEEEE
题目名称 软件包管理器 最终得分 0
用户昵称 FoolMike 运行时间 0.647 s
代码语言 Pascal 内存使用 91.54 MiB
提交时间 2015-08-01 11:54:44
显示代码纯文本
var
n,q,i,j,num,ans:longint;
f,qq:array[0..100000] of longint;
hj:array[0..5000,-1..5000]of longint;
s:string;

  procedure uninstall(num:longint);
  var
  i:longint;
  begin
  if f[num]=0 then exit;
  inc(ans);
  f[num]:=0;
  for i:=0 to hj[num,-1]-1 do
  uninstall(hj[num,i]);
  hj[num,-1]:=0;
  end;

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

read(n);
for n:=1 to n-1 do
read(qq[n]);
readln(q);
for q:=1 to q do
  begin
  readln(s);
  num:=0;j:=1;ans:=0;
  if s[1]='i' then
    begin
    for i:=length(s) downto 9 do
      begin
      num:=num+(ord(s[i])-48)*j;
      j:=j*10;
      end;
    {writeln(num);}
    while f[num]=0 do
      begin
      inc(ans);
      f[num]:=1;
      inc(hj[qq[num],-1]);
      hj[qq[num],hj[qq[num],-1]]:=num;
      num:=qq[num];
      end;
    end;
  if s[1]='u' then
    begin
    for i:=length(s) downto 11 do
      begin
      num:=num+(ord(s[i])-48)*j;
      j:=j*10;
      end;
    uninstall(num);
    end;
  writeln(ans);
  end;
close(input);
close(output);
end.