POJ 2777(涂点问线)

线段树……

Program p2777;
const
   maxl=100000;
   maxt=30;
   maxo=100000;
var
   l,t,o,i,j,k:longint;
   col:array[1..maxl*10] of longint;
   c:char;
   x,y,color:longint;
   visit:array[1..maxt] of boolean;
procedure build(l,r,root:longint);
var
   mid:longint;
begin
   if l=r then
   begin
      col[root]:=1;
      exit;
   end;
   mid:=(l+r) shr 1;
   build(l,mid,root shl  1);
   build(mid+1,r,root shl 1+1);
   col[root]:=1;
end;
procedure swap(var a,b:longint);
var
   p:longint;
begin
   p:=a;a:=b;b:=p;
end;
procedure detate(l,r,sonl,sonr,root,color:longint);
var
   i,j,mid:longint;
begin
   mid:=(l+r) shr 1;
   if l=r then
   begin
      col[root]:=color;
      exit;
   end;

   if (sonl<=l) and (r<=sonr) then
   begin
      col[root]:=color;
      exit;
   end;

   if col[root]>0 then
   begin
      col[root*2]:=col[root];
      col[root*2+1]:=col[root];
      col[root]:=-1;


   end;

   if not((mid<sonl) or (sonr<l)) then detate(l,mid,sonl,sonr,root shl 1,color);
   if not((r<sonl) or (sonr<mid+1)) then detate(mid+1,r,sonl,sonr,root shl 1+1,color);



end;
function quere(l,r,sonl,sonr,root:longint):longint;
var
   mid,i,j:longint;
begin
   quere:=0;
   mid:=(l+r) shr 1;

   if col[root]>0 then
   begin
      if not(visit[col[root]]) then
      begin
         visit[col[root]]:=true;
         exit(1);
      end;
      exit(0);
   end;


   if not((mid<sonl) or (sonr<l)) then inc(quere,quere(l,mid,sonl,sonr,root shl 1));
   if not((r<sonl) or (sonr<mid+1)) then inc(quere,quere(mid+1,r,sonl,sonr,root shl 1+1));


end;

begin
   readln(l,t,o);
   build(1,l,1);
   for i:=1 to o do
   begin
      read(c);
      if c='C' then
      begin
         readln(x,y,color);
         if x>y then swap(x,y);
         detate(1,l,x,y,1,color);
      end
      else
      begin
         readln(x,y);
         if x>y then swap(x,y);
         fillchar(visit,sizeof(visit),false);
         writeln(quere(1,l,x,y,1));
      end;
   end;
end.

POJ 3100(非二分不合作)

这题的数据太水……

居然不需要2分Log n查找……尽管我也不知道上限是多少……

Program P3100;
var
   a,b,n,i,j,dis:longint;
function pow(a,b:longint):longint;
var
   i:longint;
begin
   if a=0 then exit(0);
   if a=1 then exit(1);
   if b=0 then exit(0);
   if b=1 then exit(a)
   else
   begin
      pow:=pow(a,b shr 1);
      if (b mod 2=0) then
      begin
         exit(pow*pow);
      end
      else exit(pow*pow*a);
   end;
end;
begin
   read(b,n);
   while (b+n>0) do
   begin
      i:=0;
      while (pow(i,n)<b) do
      begin
         dis:=b-pow(i,n);
         inc(i);
      end;
      if (pow(i,n)-b>dis) then writeln(i-1) else writeln(i);


      read(b,n);
   end;
end.