#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
const int maxn = 1e5 + 10;
int n, a[maxn];
int pos[maxn], len, tag[maxn], is_zero[maxn], num[maxn];
void change(int l, int r, int c)
{
for (int i = l; i <= min(len * pos[l], r); i++)
a[i] = sqrt(a[i]);
if (pos[l] != pos[r])
for (int i = r; i >= len * pos[r] - len + 1; i--)
a[i] = sqrt(a[i]);
for (int i = pos[l] + 1; i <= pos[r] - 1; i++)
tag[i]++;
}
int cal(int l, int r, int c)
{
int ans = 0;
for (int i = l; i <= min(len * pos[l], r); i++)
{
if (a[i] == 0)
continue;
if (tag[pos[i]] >= 5)
ans += 1;
else
{
int t = a[i];
for (int j = 1; j <= tag[pos[i]]; j++)
t = sqrt(t);
ans += t;
}
}
if (pos[l] != pos[r])
for (int i = r; i >= len * pos[r] - len + 1; i--)
{
if (a[i] == 0)
continue;
if (tag[pos[i]] >= 5)
ans += 1;
else
{
int t = a[i];
for (int j = 1; j <= tag[pos[i]]; j++)
t = sqrt(t);
ans += t;
}
}
for (int i = pos[l] + 1; i <= pos[r] - 1; i++)
{
if (tag[i] >= 5)
ans += len - num[i];
else
{
for (int j = i * len - len + 1; j <= i * len; j++)
{
int t = a[j];
for (int k = 1; k <= tag[i]; k++)//开方k次
t = sqrt(t);
ans += t;
}
}
}
return ans;
}
void solve()
{
scanf("%d", &n);
len = sqrt(n);
for (int i = 1; i <= n; i++)
{
scanf("%d", &a[i]), pos[i] = (i - 1) / len + 1;
if (a[i] == 0)
is_zero[i] = 1, num[pos[i]]++;
}
for (int i = 1; i <= n; i++)
{
int opt, l, r, c;
scanf("%d%d%d%d", &opt, &l, &r, &c);
if (opt == 0)
change(l, r, c);
else
printf("%d\n", cal(l, r, c));
}
}
int main()
{
//freopen("Testin.txt", "r", stdin);
//freopen("Testout.txt", "w", stdout);
solve();
return 0;
}
原文:https://www.cnblogs.com/danzh/p/11361119.html