Bzoj3211: 花神游历各国

Posted Cyhlnj

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
}

以上是关于Bzoj3211: 花神游历各国的主要内容,如果未能解决你的问题,请参考以下文章

BZOJ3211: 花神游历各国

bzoj3211花神游历各国 线段树

BZOJ-3211: 花神游历各国 (线段树)

bzoj3211 花神游历各国 线段树,势能分析

bzoj3211: 花神游历各国(线段树)

bzoj3211花神游历各国