zoukankan      html  css  js  c++  java
  • Codeforces 903G 巧妙的线段树

    思路:

    巧妙的线段树

    想方法将网络流往数据结构方向转化

    http://www.cnblogs.com/yyf0309/p/8724558.html

    //By SiriusRen
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int N=200050;
    int n,m,q,X[N],y[N],tmp=1,xx,yy;
    ll tree[N<<2],lazy[N<<2],x[N];
    struct Node{int from,to,wei;}node[N];
    bool operator<(Node a,Node b){return a.from<b.from;}
    void insert(int l,int r,int pos,int L,int R,ll wei){
        if(l>=L&&r<=R){tree[pos]+=wei;lazy[pos]+=wei;return;}
        int mid=(l+r)>>1,lson=pos<<1,rson=pos<<1|1;
        if(mid<L)insert(mid+1,r,rson,L,R,wei);
        else if(mid>=R)insert(l,mid,lson,L,R,wei);
        else insert(l,mid,lson,L,R,wei),insert(mid+1,r,rson,L,R,wei);
        tree[pos]=min(tree[lson],tree[rson])+lazy[pos];
    }
    int main(){
        scanf("%d%d%d",&n,&m,&q);
        for(int i=2;i<=n;i++)scanf("%lld%d",&x[i-1],&y[i]);
        for(int i=1;i<=m;i++)scanf("%d%d%d",&node[i].from,&node[i].to,&node[i].wei);
        for(int i=2;i<=n;i++)insert(1,n,1,i,i,y[i]);
        sort(node+1,node+1+m);
        for(int i=1;i<=n;i++){
            for(;tmp<=m&&node[tmp].from<=i;tmp++)
                insert(1,n,1,1,node[tmp].to,node[tmp].wei);
            X[i]=x[i],x[i]+=tree[1];
        }memset(tree,0,sizeof(tree)),memset(lazy,0,sizeof(lazy));
        for(int i=1;i<=n;i++)insert(1,n,1,i,i,x[i]);
        printf("%lld
    ",tree[1]);
        while(q--){
            scanf("%d%d",&xx,&yy);
            insert(1,n,1,xx,xx,yy-X[xx]),X[xx]=yy;
            printf("%lld
    ",tree[1]);
        }
    }
  • 相关阅读:
    单片机开发 郭天祥
    OpenNI检测不到Kinect Camera和Kinect Audio了
    python中的类的成员变量以及property函数
    python lambda
    python中的括号以及元组和列表的区别
    python的self
    python exception的传递
    python的闭包
    函数里面定义函数
    在yum出问题的情况下安装某个rpm包的方法
  • 原文地址:https://www.cnblogs.com/SiriusRen/p/9190975.html
Copyright © 2011-2022 走看看