/************************************************************** Problem: 3211 User: syh0313 Language: C++ Result: Accepted Time:2020 ms Memory:11456 kb ****************************************************************/ #include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #define lch a[n].lc #define rch a[n].rc using namespace std; const int maxn=100010; int n,m,root,topt; long long v[maxn]; struct da{ int lc,rc; long long sum,ma;}a[4*maxn]; inline void updata( int n) { a[n].sum=a[lch].sum+a[rch].sum; a[n].ma=max(a[lch].ma,a[rch].ma); } void build_tree( int &n, int l, int r) { n=++topt; if (l==r) {a[n].sum=v[l]; a[n].ma=v[l]; return ;} int mid=(l+r)>>1; build_tree(lch,l,mid); build_tree(rch,mid+1,r); updata(n); } void tree_sq( int n, int L, int R, int l, int r) { if (a[n].ma<=1) return ; if (L==l && R==r && l==r) {a[n].sum= sqrt (a[n].sum); a[n].ma=a[n].sum; return ;} int mid=(L+R)>>1; if (r<=mid) tree_sq(lch,L,mid,l,r); else if (l>=mid+1) tree_sq(rch,mid+1,R,l,r); else tree_sq(lch,L,mid,l,mid),tree_sq(rch,mid+1,R,mid+1,r); updata(n); } long long qury( int n, int L, int R, int l, int r) { if (L==l && R==r) return a[n].sum; int mid=(L+R)>>1; if (r<=mid) return qury(lch,L,mid,l,r); else if (l>=mid+1) return qury(rch,mid+1,R,l,r); else return qury(lch,L,mid,l,mid)+qury(rch,mid+1,R,mid+1,r); } int main() { scanf ( "%d" ,&n); for ( int i=1;i<=n;i++) scanf ( "%lld" ,&v[i]); build_tree(root,1,n); scanf ( "%d" ,&m); while (m--) { int ff,ll,rr; scanf ( "%d%d%d" ,&ff,&ll,&rr); if (ff==1) printf ( "%lld\n" ,qury(root,1,n,ll,rr)); else tree_sq(root,1,n,ll,rr); } return 0; } |