线段树的裸题;
但是操作很奇怪,开方是不能lazy tag的
看来只能暴力修改了
但注意,开放开到1的时候就不用开,立一个flag就可以了
这可以大大的优化;
其实我是来复习线段树的
var tree:array[..] of int64;
lazy:array[..] of boolean;
a:array[..] of int64;
n,m,ch,p,q,l,r,i:longint; procedure swap(var a,b:longint);
var c:longint;
begin
c:=a;
a:=b;
b:=c;
end; procedure update(i:longint);
begin
tree[i]:=tree[i*]+tree[i*+];
lazy[i]:=lazy[i*] and lazy[i*+];
end; procedure build(i,l,r:longint);
var m:longint;
begin
if l=r then
begin
tree[i]:=a[l];
lazy[i]:=false;
end
else begin
m:=(l+r) shr ;
build(i*,l,m);
build(i*+,m+,r);
update(i);
end;
end; procedure work(i,l,r:longint);
var m:longint;
begin
if l=r then
begin
tree[i]:=trunc(sqrt(tree[i]));
if tree[i]= then lazy[i]:=true;
end
else begin
m:=(l+r) shr ;
if (p<=m) and not lazy[i*] then work(i*,l,m);
if (q>m) and not lazy[i*+] then work(i*+,m+,r);
update(i);
end;
end; function ask(i,l,r:longint):int64;
var m:longint;
begin
if (p<=l) and (q>=r) then exit(tree[i])
else begin
m:=(l+r) shr ;
ask:=;
if p<=m then ask:=ask+ask(i*,l,m);
if q>m then ask:=ask+ask(i*+,m+,r);
end;
end; begin
readln(n);
for i:= to n do
read(a[i]);
build(,,n);
readln(m);
for i:= to m do
begin
readln(ch,p,q);
if p>q then swap(p,q);
if ch= then
work(,,n)
else if ch= then
writeln(ask(,,n));
end;
end.