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

    裸题模板

    #include<iostream>
    #include<queue>
    #include<map>
    #include<vector>
    #include<cstdio>
    #include<algorithm>
    #include<stack>
    #include<string>
    #include<cstring>
    using namespace std;
    typedef long long ll;
    const int N=1e5+10;
    const int inf=0x3f3f3f3f;
    struct node{
        int l,r;
        int sum;
        int lazy;
    }tr[N<<2];
    void pushup(int u){
        tr[u].sum=tr[u<<1].sum+tr[u<<1|1].sum;
    }
    void build(int u,int l,int r){
        if(l==r){
            tr[u]={l,l,1,0};
    
        }
        else{
            int mid=l+r>>1;
            tr[u]={l,r,0,0};
            build(u<<1,l,mid);
            build(u<<1|1,mid+1,r);
            pushup(u);
        }
    }
    void pushdown(int u){
        if(tr[u].lazy){
            tr[u<<1].lazy=tr[u<<1|1].lazy=tr[u].lazy;
            tr[u<<1].sum=(tr[u<<1].r-tr[u<<1].l+1)*tr[u].lazy;
            tr[u<<1|1].sum=(tr[u<<1|1].r-tr[u<<1|1].l+1)*tr[u].lazy;
            tr[u].lazy=0;
        }
    }
    void modify(int u,int l,int r,int x){
        if(tr[u].l>=l&&tr[u].r<=r){
            tr[u].sum=(tr[u].r-tr[u].l+1)*x;
            tr[u].lazy=x;
            return ;
        }
        pushdown(u);
        int mid=tr[u].l+tr[u].r>>1;
        if(l<=mid)
            modify(u<<1,l,r,x);
        if(r>mid)
            modify(u<<1|1,l,r,x);
        pushup(u);
    }
    int main(){
        int t;
        int n;
        cin>>t;
        int cnt=1;
        while(t--){
            cin>>n;
            int m;
            cin>>m;
            int i;
            build(1,1,n);
            for(i=1;i<=m;i++){
                int x,y,z;
                scanf("%d%d%d",&x,&y,&z);
                modify(1,x,y,z);
            }
            printf("Case %d: The total value of the hook is %d.
    ",cnt++,tr[1].sum);
        }
    }
    View Code
  • 相关阅读:
    从零开始~
    SVN
    了解下几个证书~~
    重要的技术发展趋势
    求职路上英语面试试题问答大全
    C语言比java重要吗?
    开源solr搜索服务器配置
    全文索引 与 Like 的实现原理
    nginx搭建多个站点
    .Solr构建索引查询索引
  • 原文地址:https://www.cnblogs.com/ctyakwf/p/12513223.html
Copyright © 2011-2022 走看看