• 3038: 上帝造题的七分钟2 [线段树 暴力]


    3038: 上帝造题的七分钟2

    Time Limit: 3 Sec  Memory Limit: 128 MB
    Submit: 1210  Solved: 536
    [Submit][Status][Discuss]

    Description

    XLk觉得《上帝造题的七分钟》不太过瘾,于是有了第二部。
    "第一分钟,X说,要有数列,于是便给定了一个正整数数列。
    第二分钟,L说,要能修改,于是便有了对一段数中每个数都开平方(下取整)的操作。
    第三分钟,k说,要能查询,于是便有了求一段数的和的操作。
    第四分钟,彩虹喵说,要是noip难度,于是便有了数据范围。
    第五分钟,诗人说,要有韵律,于是便有了时间限制和内存限制。
    第六分钟,和雪说,要省点事,于是便有了保证运算过程中及最终结果均不超过64位有符号整数类型的表示范围的限制。
    第七分钟,这道题终于造完了,然而,造题的神牛们再也不想写这道题的程序了。"
    ——《上帝造题的七分钟·第二部》
    所以这个神圣的任务就交给你了。

    Input

    第一行一个整数n,代表数列中数的个数。
    第二行n个正整数,表示初始状态下数列中的数。
    第三行一个整数m,表示有m次操作。
    接下来m行每行三个整数k,l,r,k=0表示给[l,r]中的每个数开平方(下取整),k=1表示询问[l,r]中各个数的和。

    Output

    对于询问操作,每行输出一个回答。

    Sample Input

    10
    1 2 3 4 5 6 7 8 9 10
    5
    0 1 10
    1 1 10
    1 1 5
    0 5 8
    1 4 8

    Sample Output

    19
    7
    6

    HINT

    1:对于100%的数据,1<=n<=100000,1<=l<=r<=n,数列中的数大于0,且不超过1e12。

    2:数据不保证L<=R 若L>R,请自行交换L,R,谢谢!

    Source

    Poetize4


    同bzoj3211

    开根号减小的非常快 loglogn ?

    全部是1就没必要继续开根了

    所以col=1表示一个区间没必要继续开根(=0或=1)

    本题数据范围是1e12啊啊啊啊啊全程long long

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    using namespace std;
    #define mid ((l+r)>>1)
    #define lc x<<1
    #define rc x<<1|1
    #define lson x<<1,l,mid
    #define rson x<<1|1,mid+1,r
    const int N=1e5+5;
    typedef long long ll;
    inline ll read(){
        char c=getchar();ll x=0,f=1;
        while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
        return x*f;
    }
    int n,Q,op,ql,qr;
    struct node{
        int col;
        ll sum;
        node():col(0),sum(0){}
    }t[N<<2];
    inline void merge(int x){
        t[x].sum=t[lc].sum+t[rc].sum;
        t[x].col=t[lc].col&t[rc].col;
    }
    void build(int x,int l,int r){
        if(l==r){
            t[x].sum=read();
            if(t[x].sum==1||t[x].sum==0) t[x].col=1;
        }else{
            build(lson);
            build(rson);
            merge(x);
        }
    }
    void segSqr(int x,int l,int r,int ql,int qr){
        if(t[x].col) return;
        if(l==r){
            t[x].sum=(ll)sqrt(t[x].sum);
            if(t[x].sum==1||t[x].sum==0) t[x].col=1;
        }else{
            if(ql<=mid) segSqr(lson,ql,qr);
            if(mid<qr) segSqr(rson,ql,qr);
            merge(x);
        }
    }
    ll segQue(int x,int l,int r,int ql,int qr){
        if(ql<=l&&r<=qr) return t[x].sum;
        else{
            ll ans=0;
            if(ql<=mid) ans+=segQue(lson,ql,qr);
            if(mid<qr) ans+=segQue(rson,ql,qr);
            return ans;
        }
    }
    int main(){
        //freopen("in.txt","r",stdin);
        n=read();    
        build(1,1,n);
        Q=read();
        while(Q--){
            op=read();ql=read();qr=read();
            if(ql>qr) swap(ql,qr);
            if(op==1) printf("%lld
    ",segQue(1,1,n,ql,qr));
            else segSqr(1,1,n,ql,qr);
        }
    }
  • 相关阅读:
    global
    myTimer
    SQL SERVER 2008 阻止保存要求重新创建表的更改
    Singleton
    logger
    多线程编写
    如何:设置 Silverlight 应用程序以进行CodeUI自动化测试
    【Android】Application is not installed on your phone
    【转载】sql2005中判读视图、表、存储过程等是否存在的语句
    Windows7(win7)系统重装与破解
  • 原文地址:https://www.cnblogs.com/candy99/p/6285913.html
Copyright © 2020-2023  润新知