Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我写的有问题 求帮忙 不知大家看懂没

Posted by 1248934113 at 2012-02-08 17:01:17 on Problem 3468
program poj3468;
type
  sb=record
    l,r:longint;
    h:double;
  end;
var
n,q,i,j,l,r,w,w1:Longint;
max,h:double;
a:array[1..3000000] of double;
s:array[1..200000] of sb;
x:string;
procedure js(w,l,r:longint);
begin
  s[w].l:=l;s[w].r:=r;
  if l=r then
     begin
       s[w].h:=a[l];
       exit;
     end;
  js(w*2,l,(l+r) div 2);
  js(w*2+1,(l+r) div 2+1 ,r);
  s[w].h:=s[w*2].h+s[w*2+1].h;
end;
procedure cha(w:longint);
var
lh,rh:int64;
begin
  if (s[w].l>=l) and (s[w].r<=r)
    then begin max:=s[w].h+max; exit; end;
  if (s[w*2].l>=l) and (s[w*2].l<=r)
                or
     (s[w*2].r>=l) and (s[w*2].r<=r)
                or
     (s[w*2].l<=l) and (s[w*2].r>=r)
      then cha(w*2);
   if (s[w*2+1].l>=l) and (s[w*2+1].l<=r)
                or
     (s[w*2+1].r>=l) and (s[w*2+1].r<=r)
                or
     (s[w*2+1].l<=l) and (s[w*2+1].r>=r)
      then cha(w*2+1);
end;
procedure jia(w:longint);
begin
  if s[w].l=s[w].r then begin s[w].h:=h+s[w].h;exit;end;
  if (s[w*2].l>=l) and (s[w*2].l<=r)
                or
     (s[w*2].r>=l) and (s[w*2].r<=r)
                or
     (s[w*2].l<=l) and (s[w*2].r>=r)
      then jia(w*2);
   if (s[w*2+1].l>=l) and (s[w*2+1].l<=r)
                or
     (s[w*2+1].r>=l) and (s[w*2+1].r<=r)
                or
     (s[w*2+1].l<=l) and (s[w*2+1].r>=r)
      then jia(w*2+1);
      s[w].h:=s[w*2].h+s[w*2+1].h;
end;
begin
  readln(n,q);
  for i:=1 to n do
    read(a[i]);
    readln;
  js(1,1,n);
  for i:=1 to q do
    begin
      readln(x);
      if x[1]='Q' then
        begin
          w:=2+pos(' ',copy(x,3,length(x)-3+1));
          val(copy(x,3,w-3),l);
          val(copy(x,w+1,length(x)-w),r);
          max:=0;cha(1);
          writeln(max:0:0);
        end
       else
         begin
           w:=2+pos(' ',copy(x,3,length(x)-3+1));
           val(copy(x,3,w-3),l);
           w1:=w+pos(' ',copy(x,w+1,length(x)-w));
           val(copy(x,w+1,w1-w-1),r);
           val(copy(x,w1+1,length(x)-w1),h);
           jia(1);
         end;
    end;
end.

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator