zoukankan      html  css  js  c++  java
  • 3211:花神游历各国

    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

    解题的关键在于一个数开方6次之后值就会停止变化恒等于1或者0

    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <cstdlib>
    #include <iomanip>
    #include <cmath>
    #include <cassert>
    #include <ctime>
    #include <map>
    #include <set>
    using namespace std;
    #pragma comment(linker, "/stck:1024000000,1024000000")
    #pragma GCC diagnostic error "-std=c++11"
    #define lowbit(x) (x&(-x))
    #define max(x,y) (x>=y?x:y)
    #define min(x,y) (x<=y?x:y)
    #define MAX 100000000000000000
    #define MOD 1000000007
    #define esp 1e-9
    #define pi acos(-1.0)
    #define ei exp(1)
    #define PI 3.1415926535897932384626433832
    #define ios() ios::sync_with_stdio(true)
    #define INF 0x3f3f3f3f
    #define mem(a) (memset(a,0,sizeof(a)))
    typedef long long ll;
    const int maxn=100006;
    ll tree[maxn<<2];
    int n,m,l,r,val,vis[maxn<<2];
    void pushup(int root)
    {
        tree[root]=tree[root<<1]+tree[root<<1|1];
        vis[root]=vis[root<<1]&&vis[root<<1|1];
    }
    void build(int l,int r,int root)
    {
        if(l==r)
        {
            scanf("%lld",&tree[root]);
            if(tree[root]==0 || tree[root]==1) vis[root]=1;
            return ;
        }
        int mid=l+r>>1;
        build(l,mid,root<<1);
        build(mid+1,r,root<<1|1);
        pushup(root);
    }
    void update(int L,int R,int l,int r,int root)
    {
        int mid=l+r>>1;
        if(l==r){
            tree[root]=(ll)sqrt(tree[root]);
            if(tree[root]==0 || tree[root]==1) vis[root]=1;
            return ;
        }
        if(L<=mid && !vis[root<<1]) update(L,R,l,mid,root<<1);//标记数组为1之后此值恒定不变
        if(R>mid && !vis[root<<1|1]) update(L,R,mid+1,r,root<<1|1);
        pushup(root);
    }
    ll query(int L,int R,int l,int r,int root)
    {
        if(L<=l && R>=r) return tree[root];
        ll ans=0;
        int mid=l+r>>1;
        if(L<=mid) ans+=query(L,R,l,mid,root<<1);
        if(R>mid) ans+=query(L,R,mid+1,r,root<<1|1);
        return ans;
    }
    int main()
    {
        scanf("%d",&n);
        build(1,n,1);
        scanf("%d",&m);
        while(m--)
        {
            scanf("%d%d%d",&val,&l,&r);
            if(val==1) printf("%lld
    ",query(l,r,1,n,1));
            else update(l,r,1,n,1);
        }
        return 0;
    }
  • 相关阅读:
    QT事件(信号与槽)用法
    Debian自启动服务
    云锵投资 2020 年 09 月简报
    大数据表查询优化
    云锵投资 2020 年 08 月简报
    can't open ttyS0, error code 2
    QHostAddress 获取ip地址后 格式为"::ffff:127.0.0.1"问题
    qmake: could not exec '/home/hbg/Qt5.11.1/5.11.1/gcc_64/bin/qmake': No such file or directory
    connect to database error : Access denied for user 'root'@'localhost'
    ping 打印添加时间戳
  • 原文地址:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/9438603.html
Copyright © 2011-2022 走看看