标签:
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std ;
typedef long long ll ;
ll c[100001] ;
ll p[100001] ;
ll fa[100001] ;
int n ;
ll lowbit(ll x)
{
return x & (-x) ;
}
ll getsum(ll x)
{
ll sum = 0 ;
while(x>0)
{
sum += c[x] ;
x -= lowbit(x) ;
}
return sum ;
}
void updata(int x , ll t)
{
while(x <= n)
{
c[x] += t ;
x += lowbit(x) ;
}
}
int find(int x)
{
if(fa[x] == x) return x ;
else
{
fa[x] = find(fa[x]) ;
return fa[x] ;
}
}
int main()
{
scanf("%d" , &n) ;
for(int i = 1 ; i <= n ; i++)
{
scanf("%d" , &p[i]) ;
updata(i , p[i]) ;
fa[i] = i ;
}
fa[n+1] = n+1 ;
int q ;
scanf("%d" , &q) ;
for(int i = 1 ; i <= q ; i++)
{
int x , l , r;
scanf("%d%d%d" , &x , &l , &r) ;
if(x==1)
{
printf("%lld\n" , getsum(r) - getsum(l-1)) ;
}else
{
for(int i = find(l) ; i<=r ; i = find(i+1))
{
int t = (int)(sqrt(p[i])) ;
updata(i , t - p[i]) ;
p[i] = t ;
if(p[i] <= 1) fa[i] = find(i+1) ;
}
}
}
}
标签:
原文地址:http://blog.csdn.net/wzq_qwq/article/details/45370551