记录编号 21268 评测结果 AWTWAAWWAWTW
题目名称 售票系统 最终得分 33
用户昵称 Gravatardonny 是否通过 未通过
代码语言 Pascal 运行时间 3.255 s
提交时间 2010-11-09 09:43:02 内存使用 1.61 MiB
显示代码纯文本
program railway;
const
  er:array[1..17]of longint=(2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072);
type
  ss=record
    max,l,r:longint;
  end;
var
  i,j,k,l,o,d,n,c,s,r:longint;
  f:array[1..131072]of ss;
  max:longint;
  ge:longint;
procedure jian;
var
  i,j:longint;
begin
  for i:=1 to 17 do
    if c<=er[i] then
    begin
      j:=i+1;
      break;
    end;
  f[1].l:=1;
  f[1].r:=er[j-1];
  ge:=er[j-1]-1;
  for i:=2 to er[j]-1 do
  begin
    if (i mod 2)=0 then
    begin
      f[i].l:=f[i div 2].l;
      f[i].r:=(f[i div 2].l+f[i div 2].r)div 2;
    end
    else
    begin
      f[i].l:=((f[i div 2].l+f[i div 2].r)div 2)+1;
      f[i].r:=f[i div 2].r;
    end;
  end;
end;
procedure go(const w:longint);
begin
  if (f[w].l>o)and(f[w].r<d)then
  begin
    if f[w].max>max then max:=f[w].max
  end
  else
    if f[w*2].r>o then
    begin
      go(w*2);
      if f[(w*2)+1].l<d then
        go((w*2)+1);
    end
    else
      if f[(w*2)+1].l<d then
        go((w*2)+1);
end;
procedure zhao(x:longint);
begin
  if x<>1 then
  begin
    if f[x div 2].max<f[x].max then
    begin
      f[x div 2].max:=f[x].max;
      zhao(x div 2);
    end;
  end;
end;
begin
  assign(input,'railway.in');
  reset(input);
  assign(output,'railway.out');
  rewrite(output);
  readln(c,s,r);
  jian;
  for i:=1 to r do
  begin
    readln(o,d,n);
    max:=0;
    go(1);
    if (s-max)>=n then
    begin
      writeln('YES');
      for j:=o+1 to d do
      begin
        inc(f[ge+j].max,n);
        zhao(ge+j);
      end;
    end
    else
      writeln('NO');
  end;
  close(input);
  close(output);
end.