对一个区间两种操作:
c x y
1、使区间[x,y]的数等于其开方数(四舍五入)。
2、查询区间[x,y]的和。
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define root 1 , N , 1
#define LL long long
#define SZ 100000
int N ;
int M ;
struct segment{
int l,r;
LL sum,maxn;
}tree[SZ<<2];
LL num[SZ];
void PushUp(int rt)
{
tree[rt].sum = tree[rt<<1].sum + tree[rt<<1|1].sum;
tree[rt].maxn = max( tree[rt<<1].maxn , tree[rt<<1|1].maxn );
}
void build(int l,int r,int rt)
{
tree[rt].l = l;
tree[rt].r = r;
if( l == r )
{
LL x;
scanf("%lld",&x);
tree[rt].sum = tree[rt].maxn = x;
return ;
}
int m = ( l + r ) >> 1;
build(lson);
build(rson);
PushUp(rt);
}
void update(int l,int r,int rt)
{
if( tree[rt].l == tree[rt].r )
{
tree[rt].sum = (LL)sqrt(tree[rt].sum);//...
tree[rt].maxn = (LL)sqrt(tree[rt].maxn);
return ;
}
int m = ( tree[rt].l + tree[rt].r ) >> 1;
if( l <= m && tree[rt<<1].maxn > 1 )
update(l,r,rt<<1);
if( m < r && tree[rt<<1|1].maxn > 1 )
update(l,r,rt<<1|1);
PushUp(rt);
}
LL query(int l,int r,int rt)
{
if( l <= tree[rt].l && tree[rt].r <= r ){
return tree[rt].sum;
}
LL res = 0;
int m = (tree[rt].l + tree[rt].r) >> 1;
if( l <= m )res += query(l,r,rt<<1);
if( m < r )res += query(l,r,rt<<1|1);
return res;
}
int main()
{
while( cin >> N )
{
build(root);
cin >> M;
while( M -- )
{
int a, b , c;
scanf("%d %d %d", &a,&b,&c);
if( b > c )swap(b,c);
if( a )
cout << query( b, c, 1 ) << endl ;
else
update( b, c, 1 );
}
}
}