zoukankan      html  css  js  c++  java
  • Just a Hook HDU

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    typedef long long ll;
    const int N=1e5+10;
    struct node{
        int l,r;
        int sum;
        int add;
    }tr[N*4];
    void pushdown(int root)
    {
        if (tr[root].add)
        {
            tr[root<<1].add=tr[root].add;
            tr[root<<1|1].add=tr[root].add;
            int mid=(tr[root].l+tr[root].r)/2;
            tr[root<<1].sum=tr[root].add*(mid-tr[root].l+1);
            tr[root<<1|1].sum=tr[root].add*(tr[root].r-mid);
            tr[root].add=0;
        }
    }
    void pushup(int u)
    {
        tr[u].sum=tr[u<<1].sum+tr[u<<1|1].sum;
    }
    void build(int root, int l, int r)
    {
        tr[root].l=l;
        tr[root].r=r;
        tr[root].add=0;
        tr[root].sum=0;
        if(l==r)
        {
            tr[root].sum = 1;
            return ;
        }
        int mid=l+r>>1;
        build(root<<1,l,mid);
        build(root<<1|1,mid+1,r);
        pushup(root);
    }
    void update(int root,int ql,int qr,int c)
    {
        if (ql>tr[root].r||qr<tr[root].l)
            return;
        if (ql<=tr[root].l&&tr[root].r<= qr)
        {
            tr[root].sum=(tr[root].r-tr[root].l+1)*c;
            tr[root].add=c;
        }
        else
        {
            pushdown(root);
            int mid=tr[root].l+tr[root].r>>1;
            update(root<<1,ql,qr,c);
            update(root<<1|1,ql,qr,c);
            pushup(root);
        }
    }
    int main()
    {
        int t,cnt=0;
        scanf("%d",&t);
        while(t--)
        {
            int n,q;
            scanf("%d%d",&n,&q);
            build(1,1,n);
            while(q--)
            {
                int l,r,op;
                scanf("%d%d%d",&l,&r,&op);
                update(1,l,r,op);
            }
            printf("Case %d: The total value of the hook is %d.
    ", ++cnt, tr[1].sum);
        }
    }
     
  • 相关阅读:
    ExtJs系列教程
    linux 服务器时间 timedatectl命令时间时区操作详解
    aws CloudWatch Events
    AWS Shield
    aws ssm指令
    failed to set bridge addr: "cni0" already has an IP address different from 10.244.0.1/24
    AWS Systems Manager
    Amazon Inspector
    AWS 安全培训
    Amazon Inspector
  • 原文地址:https://www.cnblogs.com/QingyuYYYYY/p/12293795.html
Copyright © 2011-2022 走看看