#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#define N 100010
using namespace std;
struct Node
{
__int64 sum;
int cur;
bool is_low;
bool is_leaf;
}tree[N<<2];
int n;
inline void push_up( int rt )
{
tree[rt].sum = tree[rt<<1].sum+tree[rt<<1|1].sum;
if( tree[rt<<1].is_low && tree[rt<<1|1].is_low ) tree[rt].is_low = true;
}
inline void build( int l, int r, int rt )
{
tree[rt].sum = 0;
tree[rt].is_low = false;
tree[rt].is_leaf = false;
if( l == r )
{
scanf("%I64d",&tree[rt].sum );
tree[rt].is_low = false;
tree[rt].is_leaf = true;
return ;
}
int m = (l+r)>>1;
build( l,m,rt<<1 );
build( m+1,r,rt<<1|1 );
push_up(rt);
}
void update( int L, int R, int l, int r, int rt )
{
if( tree[rt].is_low || tree[rt].is_leaf )
{
if( tree[rt].is_leaf )
{
tree[rt].sum =(__int64)sqrt((long double)tree[rt].sum);
if( tree[rt].sum <= 1 ) tree[rt].is_low = true;
}
return ;
}
int m = (l+r)>>1;
if( m >= L ) update(L,R,l,m,rt<<1);
if( m < R ) update( L,R,m+1,r,rt<<1|1 );
push_up(rt);
}
__int64 query( int L, int R, int l, int r, int rt )
{
__int64 s = 0;
if( L<=l && r<=R )
{
return tree[rt].sum;
}
int m = (l+r)>>1;
if( L <= m ) s+=query(L,R,l,m,rt<<1);
if( m < R ) s+=query(L,R,m+1,r,rt<<1|1);
return s;
}
int main()
{
for( int cas = 1, Q, t, l, r; scanf("%d",&n)!=EOF; cas ++ )
{
build(1,n,1);
scanf("%d",&Q);
printf("Case #%d:\n",cas);
while( Q -- )
{
scanf("%d%d%d",&t,&l,&r);
if( l>r ) swap(l,r);
if( t == 0 )
update(l,r,1,n,1);
else
printf("%I64d\n",query(l,r,1,n,1));
}
printf("\n");
}
return 0;
}
hdu 4027
最新推荐文章于 2015-12-28 17:24:23 发布