一个没调好的程序
1 program rrr(input,output); 2 type 3 treetype=record 4 l,r,d:longint; 5 xy,x,y,x2,s,t:int64; 6 end; 7 var 8 a:array[0..400040]of treetype; 9 x,y,s1,s2:array[0..100010]of int64; 10 j,s,t,sx,sy,sxy,sx2:int64; 11 n,m,i,opt,l,r:longint; 12 procedure build(k,l,r:longint); 13 var 14 mid,i:longint; 15 begin 16 a[k].l:=l;a[k].r:=r;a[k].d:=0;a[k].s:=0;a[k].t:=0; 17 if l=r then begin a[k].x:=x[l];a[k].y:=y[l];a[k].xy:=x[l]*y[l];a[k].x2:=x[l]*x[l];exit; end; 18 mid:=(l+r)>>1;i:=k+k; 19 build(i,l,mid);build(i+1,mid+1,r); 20 a[k].x:=a[i].x+a[i+1].x;a[k].y:=a[i].y+a[i+1].y;a[k].xy:=a[i].xy+a[i+1].xy;a[k].x2:=a[i].x2+a[i+1].x2; 21 end; 22 procedure pushdown(k:longint); 23 var 24 i:longint; 25 begin 26 if a[k].l=a[k].r then exit; 27 if (a[k].d=0) and (a[k].s=0) and (a[k].t=0) then exit; 28 if a[k].d=1 then 29 begin 30 i:=k+k;a[i].x:=s1[a[i].r]-s1[a[i].l-1];a[i].y:=a[i].x;a[i].x2:=s2[a[i].r]-s2[a[i].l-1];a[i].xy:=a[i].x2;a[i].d:=1;a[i].s:=0;a[i].t:=0; 31 inc(i);a[i].x:=s1[a[i].r]-s1[a[i].l-1];a[i].y:=a[i].x;a[i].x2:=s2[a[i].r]-s2[a[i].l-1];a[i].xy:=a[i].x2;a[i].d:=1;a[i].s:=0;a[i].t:=0; 32 a[k].d:=0; 33 end; 34 if (a[k].s=0) and (a[k].t=0) then exit; 35 i:=k+k;j:=a[i].r-a[i].l+1; 36 a[i].x2:=a[i].x2+2*a[k].s*a[i].x+s*s*j;a[i].xy:=a[i].xy+a[k].s*a[i].y+a[k].t*a[i].x+s*t*j; 37 a[i].x:=a[i].x+j*a[k].s;a[i].y:=a[i].y+j*a[k].t;inc(a[i].s,a[k].s);inc(a[i].t,a[k].t); 38 inc(i);j:=a[i].r-a[i].l+1; 39 a[i].x2:=a[i].x2+2*a[k].s*a[i].x+s*s*j;a[i].xy:=a[i].xy+a[k].s*a[i].y+a[k].t*a[i].x+s*t*j; 40 a[i].x:=a[i].x+j*a[k].s;a[i].y:=a[i].y+j*a[k].t;inc(a[i].s,a[k].s);inc(a[i].t,a[k].t); 41 a[k].s:=0;a[k].t:=0; 42 end; 43 procedure change1(k:longint); 44 var 45 mid,i:longint; 46 begin 47 pushdown(k); 48 if (l<=a[k].l) and (a[k].r<=r) then 49 begin 50 j:=a[k].r-a[k].l+1; 51 a[k].x2:=a[k].x2+2*s*a[k].x+s*s*j;a[k].xy:=a[k].xy+s*a[k].y+t*a[k].x+s*t*j; 52 a[k].x:=a[k].x+j*s;a[k].y:=a[k].y+j*t;a[k].s:=s;a[k].t:=t; 53 exit; 54 end; 55 mid:=(a[k].l+a[k].r)>>1;i:=k+k; 56 if l<=mid then change1(i); 57 if mid<r then change1(i+1); 58 a[k].x:=a[i].x+a[i+1].x;a[k].y:=a[i].y+a[i+1].y;a[k].xy:=a[i].xy+a[i+1].xy;a[k].x2:=a[i].x2+a[i+1].x2; 59 end; 60 procedure change2(k:longint); 61 var 62 mid,i:longint; 63 begin 64 pushdown(k); 65 if (l<=a[k].l) and (a[k].r<=r) then 66 begin 67 a[k].x:=s1[a[k].r]-s1[a[k].l-1];a[k].y:=a[k].x;a[k].x2:=s2[a[k].r]-s2[a[k].l-1];a[k].xy:=a[k].x2;a[k].d:=1; 68 j:=a[k].r-a[k].l+1; 69 a[k].x2:=a[k].x2+2*s*a[k].x+s*s*j;a[k].xy:=a[k].xy+s*a[k].y+t*a[k].x+s*t*j; 70 a[k].x:=a[k].x+j*s;a[k].y:=a[k].y+j*t;a[k].s:=s;a[k].t:=t; 71 exit; 72 end; 73 mid:=(a[k].l+a[k].r)>>1;i:=k+k; 74 if l<=mid then change2(i); 75 if mid<r then change2(i+1); 76 a[k].x:=a[i].x+a[i+1].x;a[k].y:=a[i].y+a[i+1].y;a[k].xy:=a[i].xy+a[i+1].xy;a[k].x2:=a[i].x2+a[i+1].x2; 77 end; 78 procedure query(k:longint); 79 var 80 mid:longint; 81 begin 82 pushdown(k); 83 if (l<=a[k].l) and (a[k].r<=r) then 84 begin inc(sx,a[k].x);inc(sy,a[k].y);inc(sx2,a[k].x2);inc(sxy,a[k].xy);exit; end; 85 mid:=(a[k].l+a[k].r)>>1; 86 if l<=mid then query(k+k); 87 if mid<r then query(k+k+1); 88 end; 89 begin 90 assign(input,'relative.in');assign(output,'relative.out');reset(input);rewrite(output); 91 readln(n,m); 92 for i:=1 to n do read(x[i]);for i:=1 to n do read(y[i]); 93 build(1,1,n); 94 s1[0]:=0;s2[0]:=0;j:=0;while j<n do begin inc(j);s1[j]:=s1[j-1]+j;s2[j]:=s2[j-1]+j*j; end; 95 for i:=1 to m do 96 begin 97 read(opt,l,r); 98 if opt=1 then 99 begin 100 sx:=0;sx2:=0;sy:=0;sxy:=0;query(1); 101 j:=r-l+1;writeln(sx,' ',sy,' ',sx2,' ',sxy);//writeln((j*sxy-sx*sy)/(j*sx2-sx*sx):0:10); 102 end 103 else begin readln(s,t);if opt=2 then change1(1) else change2(1); end; 104 end; 105 close(input);close(output); 106 end.