题解:拿到此题我有些懵了——要是说加法乘法的话,至少还能通过标记来进行整个区间的维护,可是这个怎么办?我只好尝试了下暴力修改,然后又突然想到了一个问题——当某个点的值原来就是0或者1时,开方操作将无法改变其大小——这样就有了一个优化,只要某个区间内全部为0或者1,则可以在修改操作时无视之,对于区间这一性质如何识别,则只要另立一个标记,只要它的两个子树都有了标记,则它也被标记,这个向来不难维护。
然后我就这么Submit了一下,结果50分TT,查了20多分钟才发现题目中不保证L<=R(HansBug:TT phile:话说你为何总是那么充满喜剧色彩。。。),然后就Accept了,再然后就没有然后了^_^(难得代码小于100行不容易啊)
1 var
2 i,j,k,l,m,n:longint;
3 a,b,c:array[0..1000000] of int64;
4 procedure swap(var x,y:longint);inline;
5 var z:longint;
6 begin
7 z:=x;x:=y;y:=z;
8 end;
9 function max(x,y:longint):longint;inline;
10 begin
11 if x>y then max:=x else max:=y;
12 end;
13 function min(x,y:longint):longint;inline;
14 begin
15 if x<y then min:=x else min:=y;
16 end;
17 procedure built(z,x,y:longint);inline;
18 begin
19 if x=y then
20 begin
21 a[z]:=c[x];
22 if a[z]<=1 then b[z]:=1 else b[z]:=0;
23 end
24 else
25 begin
26 built(z*2,x,(x+y) div 2);
27 built(z*2+1,(x+y) div 2+1,y);
28 a[z]:=a[z*2]+a[z*2+1];
29 if (b[z*2]=1) and (b[z*2+1]=1) then b[z]:=1 else b[z]:=0;
30 end;
31 end;
32 function op(z,x,y,l,r:longint):int64;inline;
33 var
34 a1,a2,a3:int64;
35 begin
36 if l>r then exit(0);
37 if (x=l) and (y=r) then if b[z]=1 then exit(0);
38 if (x=y) then
39 begin
40 a1:=a[z];
41 a[z]:=trunc(sqrt(a[z]));
42 if a[z]<=1 then b[z]:=1;
43 exit(a[z]-a1);
44 end;
45 a2:=op(z*2,x,(x+y) div 2,l,min(r,(x+y) div 2));
46 a3:=op(z*2+1,(x+y) div 2+1,y,max(l,(x+y) div 2+1),r);
47 a[z]:=a[z]+a2+a3;
48 if (b[z*2]=1) and (b[z*2+1]=1) then b[z]:=1;
49 exit(a2+a3);
50 end;
51 function cal(z,x,y,l,r:longint):int64;inline;
52 begin
53 if l>r then exit(0);
54 if (x=l) and (y=r) then exit(a[z]);
55 exit(cal(z*2,x,(x+y) div 2,l,min(r,(x+y) div 2))+cal(z*2+1,(x+y) div 2+1,y,max(l,(x+y) div 2+1),r));
56 end;
57 begin
58 readln(n);
59 for i:=1 to n do read(c[i]);
60 readln;
61 built(1,1,n);
62 readln(m);
63 for i:=1 to m do
64 begin
65 readln(j,k,l);
66 if k>l then swap(k,l);
67 case j of
68 0:op(1,1,n,k,l);
69 1:writeln(cal(1,1,n,k,l));
70 end;
71 end;
72 readln;
73 end.
74