记录编号 116057 评测结果 AAAAAAAAAA
题目名称 [HNOI 2010] 弹飞绵羊 最终得分 100
用户昵称 GravatarC语言入门 是否通过 通过
代码语言 Pascal 运行时间 5.040 s
提交时间 2014-08-24 11:36:00 内存使用 2.46 MiB
显示代码纯文本
var
 n,m,ans,i,j,k,l,now:longint;
 a,next,long:array [1..200000] of longint;
function dep(k:longint):longint;
begin
 exit((k-1) div l+1);
end;
function min(a,b:longint):longint;
begin
 if a>b then exit(b)
        else exit(a);
end;
begin
assign (input,'bzoj_2002.in');
assign (output,'bzoj_2002.out');
reset (input);
rewrite (output);
 read(n);
 for i:=1 to n do
  read(a[i]);
 l:=trunc(sqrt(n));
 for i:=n downto 1 do
  begin
   if (dep(i+a[i])<>dep(i))or(i+a[i]>n) then
    begin
     long[i]:=1;
     next[i]:=i+a[i];
    end
                                        else
    begin
     long[i]:=1+long[i+a[i]];
     next[i]:=next[i+a[i]];
    end;
  end;
 read(m);
 for k:=1 to m do
  begin
   read(i);
   if i=1 then
    begin
     read(now);
     inc(now);
     ans:=0;
     while now<=n do
      begin
       ans:=ans+long[now];
       now:=next[now];
      end;
     writeln(ans);
    end
          else
    begin
     read(j,now);
     inc(j);
     a[j]:=now;
     for i:=min(n,dep(j)*l) downto (dep(j)-1)*l+1 do
      begin
       if (dep(i+a[i])<>dep(i))or(i+a[i]>n) then
        begin
         long[i]:=1;
         next[i]:=i+a[i];
        end
                                        else
       begin
        long[i]:=1+long[i+a[i]];
        next[i]:=next[i+a[i]];
       end;
      end;
    end;
  end;
close (input);
close (output);
end.