#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
using namespace std;
ll lc(ll p){return p<<1;}
ll rc(ll p){return p<<1|1;}
ll SH[maxn<<2],sum[maxn<<2],maxt[maxn<<2];
ll m,n;
ll cnt;
void push_up(ll x){
maxt[x]=max(maxt[lc(x)],maxt[rc(x)]);
sum[x]=sum[lc(x)]+sum[rc(x)];
}
void build(ll l,ll r,ll x){
if(l==r){
sum[x]=maxt[x]=SH[l];
return;
}
ll mid=(l+r)>>1;
build(l,mid,lc(x));
build(mid+1,r,rc(x));
push_up(x);
}
void change(ll x,ll l,ll r,ll L,ll R){
if(l==r&&L<=l&&r<=R){
sum[x]=maxt[x]=sqrt(sum[x]);
return;
}
ll mid=(l+r)>>1;
if(L<=mid&&maxt[lc(x)]>1) change(lc(x),l,mid,L,R);
if(mid<R&&maxt[rc(x)]>1) change(rc(x),mid+1,r,L,R);
push_up(x);
}
ll query(ll x,ll l,ll r,ll L,ll R){
if(L<=l&&r<=R) return sum[x];
ll mid=(l+r)>>1;
ll ans=0;
if(mid>=L) ans+=query(lc(x),l,mid,L,R);
if(mid<R) ans+=query(rc(x),mid+1,r,L,R);
return ans;
}
int main(){
cin.tie(0); cout.tie(0);
while (cin >> n){
cout << "Case #" << ++ cnt << ":\n";
for(ll i=1;i<=n;i++){
cin>>SH[i];
}
build(1, n, 1);
cin >> m;
while (m --){
ll opt,l,r;
cin>>opt>>l>>r;
if(l>r) swap(l,r);
if (opt == 0){
change(1,1,n,l,r);
}
else{
cout<<query(1,1,n,l,r)<<endl;
}
}
cout << endl;
memset(SH, 0, sizeof(SH));
}
/* cin>>n;
for(ll i=1;i<=n;i++){
cin>>SH[i];
}
build(1,n,1);
cin>>m;
while(m--){
ll opt,l,r;
cin>>opt>>l>>r;
if(l>r) swap(l,r);
if(opt==0){
change(1,1,n,l,r);
}else{
cout<<query(1,1,n,l,r)<<endl;
}
}*/
return 0;
}
关键是我花神游历各国 A 了,只是改个输出格式