hdu 4027

#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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值