Bzoj3211: 花神游历各国

题面

Bzoj

Sol

暴力开根,一个数开根到小于等于\(1\)就不用管了,维护区间\(max\)\(max<=1\)就不用管这个区间,线段树

# include <bits/stdc++.h>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const int _(1e5 + 5);

IL int Input(){
    RG int x = 0, z = 1; RG char c = getchar();
    for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
    for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
    return x * z;
}

int n, m;
ll mx[_ << 2], sum[_ << 2];

IL void Build(RG int x, RG int l, RG int r){
    if(l == r){
        mx[x] = sum[x] = Input();
        return;
    }
    RG int mid = (l + r) >> 1, ls = x << 1, rs = x << 1 | 1;
    Build(ls, l, mid), Build(rs, mid + 1, r);
    mx[x] = max(mx[ls], mx[rs]), sum[x] = sum[ls] + sum[rs];
}

IL void Modify(RG int x, RG int l, RG int r, RG int L, RG int R){
    if(mx[x] <= 1) return;
    if(l == r){
        sum[x] = mx[x] = sqrt(mx[x]);
        return;
    }
    RG int mid = (l + r) >> 1, ls = x << 1, rs = x << 1 | 1;
    if(L <= mid) Modify(ls, l, mid, L, R);
    if(R > mid) Modify(rs, mid + 1, r, L, R);
    mx[x] = max(mx[ls], mx[rs]), sum[x] = sum[ls] + sum[rs];
}

IL ll Query(RG int x, RG int l, RG int r, RG int L, RG int R){
    if(L <= l && R >= r) return sum[x];
    RG int mid = (l + r) >> 1; RG ll ret = 0;
    if(L <= mid) ret = Query(x << 1, l, mid, L, R);
    if(R > mid) ret += Query(x << 1 | 1, mid + 1, r, L, R);
    return ret;
}

int main(RG int argc, RG char* argv[]){
    n = Input(), Build(1, 1, n), m = Input();
    for(RG int i = 1; i <= m; ++i){
        RG int k = Input(), l = Input(), r = Input();
        if(k == 1) printf("%lld\n", Query(1, 1, n, l, r));
        else Modify(1, 1, n, l, r);
    }
    return 0;
}

转载于:https://www.cnblogs.com/cjoieryl/p/8461435.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值