zoukankan      html  css  js  c++  java
  • hdu 1698

    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <string>
    #include <vector>
    #include <list>
    #include <map>
    #include <queue>
    #include <stack>
    #include <bitset>
    #include <algorithm>
    #include <numeric>
    #include <functional>
    using namespace std;
    #define LL long long
    #define DB double
    #define N 100500
    const int INF = 0x3f3f3f3f;
    const LL INFF = 1LL << 60;
    const DB EPS = 1e-9;
    const DB OO = 1e15;
    const DB PI = acos(-1.0);
    int sum[N*4],col[N*4],ql,qr,v;
    void Pushup(int rt)
    {
        sum[rt] = sum[rt<<1] + sum[rt<<1|1];
    }
    void build(int rt,int l,int r)
    {
        sum[rt] = 1;
        col[rt] = 0;
        if(l == r) {return ;}
        int m = (l+r)>>1;
        build(rt<<1,l,m);
        build(rt<<1|1,m+1,r);
        Pushup(rt);
        return ;
    }
    void Pushdown(int rt,int m)
    {
        if(col[rt])
        {
            col[rt<<1] = col[rt<<1|1] = col[rt];
            sum[rt<<1] = (m-(m>>1))*col[rt];
            sum[rt<<1|1] = (m>>1)*col[rt];
            col[rt] = 0;
            return ;
        }
    }
    void updata(int rt,int l,int r)
    {
        if(l>=ql&&r<=qr)
        {
            sum[rt] = (r-l+1)*v;
            col[rt] = v;
           // Pushup(rt);
            return ;
        }
        Pushdown(rt,r-l+1);
        int m = (l+r)>>1;
        if(ql<=m) updata(rt<<1,l,m);
        if(m<qr) updata(rt<<1|1,m+1,r);
        Pushup(rt);
    }
    int main()
    {
        int n,m,t,cas = 1;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d %d",&n,&m);
            build(1,1,n);
            while(m--)
            {
                scanf("%d %d %d",&ql,&qr,&v);
                updata(1,1,n);
            }
            printf("Case %d: The total value of the hook is %d.
    ",cas++,sum[1]);
        }
        return 0;
    }
    View Code

    线段树区间修改

  • 相关阅读:
    K8s--09 编写mysql的持久化deployment
    K8s--08 prometheus监控
    K8s--07 configMap资源
    K8s--06 K8s数据持久化
    k8S--05 K8s控制器类型
    k8s--04 部署harbor作为k8s镜像仓库
    K8s--03 资源类型
    K8s--02 K8S部署
    K8s--01 Kubernetes简介
    video2gift环境安装(Theano等)
  • 原文地址:https://www.cnblogs.com/llei1573/p/3912974.html
Copyright © 2011-2022 走看看