暴力分块
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+10;
using ll = long long;
ll b[N],w[N];
int l[N],r[N],belong[N];
int n,q,len,tot;
inline void init()
{
len = sqrt(n),tot = (n+len-1)/len;
for(int i=1;i<=tot;++i)l[i] = r[i-1]+1,r[i] = i*len;
r[tot] = n;
for(int i=1;i<=tot;++i){
for(int j=l[i];j<=r[i];++j)
b[i]+=w[j],belong[j] = i;
}
}
inline void modify(int ql,int qr){
int p = belong[ql],q = belong[qr];
if(p==q){
for(int i=ql;i<=qr;++i)
b[p]-=w[i],w[i] = sqrt(w[i]),b[p]+=w[i];
return;
}
for(int i=ql;i<=r[p];++i) b[p]-=w[i],w[i] = sqrt(w[i]),b[p]+=w[i];
for(int i=qr;i>=l[q];--i) b[q]-=w[i],w[i] = sqrt(w[i]),b[q]+=w[i];
for(int i=p+1;i<=q-1;++i){
if(b[i]==r[i]-l[i]+1)continue;
for(int j=l[i];j<=r[i];++j)
b[i]-=w[j],w[j] = sqrt(w[j]),b[i]+=w[j];
}
}
inline ll query(int ql,int qr){
int p = belong[ql],q = belong[qr];
ll res = 0;
if(p==q){
for(int i=ql;i<=qr;++i)
res+=w[i];
return res;
}
for(int i=ql;i<=r[p];++i)res+=w[i];
for(int i=qr;i>=l[q];--i)res+=w[i];
for(int i=p+1;i<=q-1;++i)res+=b[i];
return res;
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n;
q = n;
for(int i=1;i<=n;i++)cin>>w[i];
init();
while(q--){
int op,ql,qr,c;cin>>op>>ql>>qr>>c;
//if(ql>qr)swap(ql,qr);
if(!op)modify(ql,qr);
else cout<<query(ql,qr)<<"\n";
}
return 0;
}