题面
Sol
暴力开根,一个数开根到小于等于\(1\)就不用管了,维护区间\(max\),\(max<=1\)就不用管这个区间,线段树
# include <bits/stdc++.h>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const int _(1e5 + 5);
IL int Input(){
RG int x = 0, z = 1; RG char c = getchar();
for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
return x * z;
}
int n, m;
ll mx[_ << 2], sum[_ << 2];
IL void Build(RG int x, RG int l, RG int r){
if(l == r){
mx[x] = sum[x] = Input();
return;
}
RG int mid = (l + r) >> 1, ls = x << 1, rs = x << 1 | 1;
Build(ls, l, mid), Build(rs, mid + 1, r);
mx[x] = max(mx[ls], mx[rs]), sum[x] = sum[ls] + sum[rs];
}
IL void Modify(RG int x, RG int l, RG int r, RG int L, RG int R){
if(mx[x] <= 1) return;
if(l == r){
sum[x] = mx[x] = sqrt(mx[x]);
return;
}
RG int mid = (l + r) >> 1, ls = x << 1, rs = x << 1 | 1;
if(L <= mid) Modify(ls, l, mid, L, R);
if(R > mid) Modify(rs, mid + 1, r, L, R);
mx[x] = max(mx[ls], mx[rs]), sum[x] = sum[ls] + sum[rs];
}
IL ll Query(RG int x, RG int l, RG int r, RG int L, RG int R){
if(L <= l && R >= r) return sum[x];
RG int mid = (l + r) >> 1; RG ll ret = 0;
if(L <= mid) ret = Query(x << 1, l, mid, L, R);
if(R > mid) ret += Query(x << 1 | 1, mid + 1, r, L, R);
return ret;
}
int main(RG int argc, RG char* argv[]){
n = Input(), Build(1, 1, n), m = Input();
for(RG int i = 1; i <= m; ++i){
RG int k = Input(), l = Input(), r = Input();
if(k == 1) printf("%lld\n", Query(1, 1, n, l, r));
else Modify(1, 1, n, l, r);
}
return 0;
}