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


    3211: 花神游历各国

    Time Limit: 5 Sec  Memory Limit: 128 MB
    Submit: 5692  Solved: 2114
    [Submit][Status][Discuss]

    Description

     

    Input

     

    Output

    每次x=1时,每行一个整数,表示这次旅行的开心度

    Sample Input

    4

    1 100 5 5

    5

    1 1 2

    2 1 2

    1 1 2

    2 2 3

    1 1 4

    Sample Output

    101

    11

    11

    HINT

    对于100%的数据, n ≤ 100000,m≤200000 ,data[i]非负且小于10^9

    Source

    SPOJ2713 gss4 数据已加强

    裸题。

    #include<bits/stdc++.h>
    #define rep(i,a,b) for(int i=a;i<=b;i++)
    #define ll long long
    using namespace std;
    const int maxn=400010;
    int Mx[maxn]; ll sum[maxn];
    void pushup(int Now){
        sum[Now]=sum[Now<<1]+sum[Now<<1|1];
        Mx[Now]=max(Mx[Now<<1],Mx[Now<<1|1]);
    }
    void build(int Now,int L,int R)
    {
        if(L==R) {
            scanf("%d",&Mx[Now]);sum[Now]=Mx[Now];
            return ;
        }
        int Mid=(L+R)>>1;
        build(Now<<1,L,Mid); build(Now<<1|1,Mid+1,R);
        pushup(Now);
    }
    ll query(int Now,int L,int R,int l,int r)
    {
        if(l<=L&&r>=R) return sum[Now];
        int Mid=(L+R)>>1; ll res=0;
        if(l<=Mid) res+=query(Now<<1,L,Mid,l,r);
        if(r>Mid) res+=query(Now<<1|1,Mid+1,R,l,r);
        return res;
    }
    void Sqrt(int Now,int L,int R)
    {
        if(L==R){ sum[Now]=Mx[Now]=sqrt(Mx[Now]); return ;}
        if(Mx[Now]<=1) return ;
        int Mid=(L+R)>>1;
        Sqrt(Now<<1,L,Mid); Sqrt(Now<<1|1,Mid+1,R);
        pushup(Now);
    }
    void update(int Now,int L,int R,int l,int r)
    {
        if(Mx[Now]<=1) return ;
        if(l<=L&&r>=R){ Sqrt(Now,L,R);return ;}
        int Mid=(L+R)>>1;
        if(l<=Mid) update(Now<<1,L,Mid,l,r);
        if(r>Mid) update(Now<<1|1,Mid+1,R,l,r);
        pushup(Now);
    }
    int main()
    {
        int N,M,L,R,opt;
        scanf("%d",&N);
        build(1,1,N);
        scanf("%d",&M);
        rep(i,1,M){
            scanf("%d%d%d",&opt,&L,&R);
            if(opt==1) printf("%lld
    ",query(1,1,N,L,R));
            else update(1,1,N,L,R);
        }
        return 0;
    }
  • 相关阅读:
    B-Suffix Array
    1 or 2
    Boundary
    Fake Maxpooling
    Cover the Tree
    Omkar and Circle
    20.5.31
    Yet Another Yet Another Task
    Codeforces Round #373 (Div. 2)E. Sasha and Array +线段树+矩阵快速幂
    2018 Multi-University Training Contest 2(Naive Operations ) hdu6315
  • 原文地址:https://www.cnblogs.com/hua-dong/p/9990824.html
Copyright © 2020-2023  润新知