• 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
  • 相关阅读:
    网摘习惯
    关于Application.DoEvents()
    五句话足以改变一生
    ActionForm中reset()的用法
    Java的MD5加密和解密类
    ibatis主键自动生成
    Parameter index out of range (3 > number of parameters
    ibatis 2.0 3.0 DTD
    SmartUpload在servlet中使用方法
    The prefix "tx" for element "tx:annotationdriven" is not bound.
  • 原文地址:https://www.cnblogs.com/ctyakwf/p/12513223.html
Copyright © 2020-2023  润新知