zoukankan      html  css  js  c++  java
  • 在给定的区间上对每个数都开方 最后还是在一段上求和

    #include<algorithm>
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<queue>
    #include<math.h>
    using namespace std;
    #define N 100005
    #define lson rood<<1
    #define rson rood<<1|1
    long long w[N];
    struct node
    {
        int len,l,r,mid;
        long long v;
    }a[N<<2];
    void q(int rood,int l,int r)
    {
        a[rood].l=l;a[rood].r=r;a[rood].mid=(r+l)/2;
        a[rood].len=(r-l+1);
        if(l==r)
        {
            a[rood].v=w[l];
            return ;
        }
        q(lson,l,a[rood].mid);
        q(rson,a[rood].mid+1,r);
        a[rood].v=a[lson].v+a[rson].v;
    }
    void qq(int rood,int l,int r)
    {
        if(a[rood].v==a[rood].len)
            return ;
        if(a[rood].l==a[rood].r)
        {
            a[rood].v=(long long)(sqrt)(a[rood].v*1.0);
            return ;
        }
        if(a[rood].mid>=r) qq(lson,l,r);
        else if(a[rood].mid<l) qq(rson,l,r);
        else
        {
            qq(lson,l,a[rood].mid);
            qq(rson,a[rood].mid+1,r);
        }
        a[rood].v=a[lson].v+a[rson].v;
    }
    long long qqq(int rood,int l,int r)
    {
        if(a[rood].l==l&&a[rood].r==r)
            return a[rood].v;
        if(a[rood].mid>=r) return qqq(lson,l,r);
        else if(a[rood].mid<l) return qqq(rson,l,r);
        else
        {
            return qqq(lson,l,a[rood].mid)+qqq(rson,a[rood].mid+1,r);
        }
    }
    int main()
    {
        int n,e,f,g,m,t=1;
        while(scanf("%d",&n)!=EOF)
        {
            for(int i=1;i<=n;i++)
                scanf("%lld",&w[i]);
            q(1,1,n);
            scanf("%d",&m);
            printf("Case #%d:
    ",t++);
            for(int i=0;i<m;i++)
            {
                scanf("%d%d%d",&g,&e,&f);
                if(e>f) swap(e,f);
                if(g==0) qq(1,e,f);
                else printf("%lld
    ",qqq(1,e,f));
            }
            printf("
    ");
        }
        return 0;
    }

    http://acm.hdu.edu.cn/showproblem.php?pid=4027

  • 相关阅读:
    字符匹配算法之KMP
    rabbitmq_hearbeat
    rabbitmq_config
    postgres SQL编译过程
    postgres启动过程分析
    postgres源码目录结构
    Js两种post方式(转)
    PHP-MySQL,PHP-MySQLi,PDO的差异
    CSS属性中Display与Visibility的不同
    PHP中include路径修改
  • 原文地址:https://www.cnblogs.com/a719525932/p/5667291.html
Copyright © 2011-2022 走看看