设为首页 加入收藏

TOP

HDU 1698 Just a Hook(线段树成段更新)
2015-07-20 17:52:58 来源: 作者: 【 】 浏览:1
Tags:HDU 1698 Just Hook 线段 成段 更新

题意很简单:1-n个钩子初始价值是1,然后题目给出Q个操作,x y z,将x->y的钩子价值改为z,最后输出n个钩子的总价值。

知识点:线段树的成段更新。


lazy操作,在代码中的主要实现就是pudown操作了。当你要用的时候,就更新值,不然就仅仅标记它。


#include
  
   
#include
   
     #include
    
      #include
     
       #include
      
        #include
       
         #include
        
          #include
         
           #include
          
            #include
            #define MAXN 111111 #define MOD 1000000007 #define INF 0x7fffffff #define EPS 1e-8 #define PI acos(-1.0) #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define bug(a) cout<<"bug---->"<
            
             >1))*col[rt]; sum[rt<<1|1]=(len>>1)*col[rt]; col[rt]=0; } } void build(int l,int r,int rt) { col[rt]=0; sum[rt]=1; if(l==r) return; int m=(l+r)>>1; build(lson); build(rson); } void update(int L,int R,int c,int l,int r,int rt) { if(L<=l&&r<=R) { col[rt]=c; sum[rt]=c*(r-l+1); return; } pushdown(rt,r-l+1); int m=(l+r)>>1; if(L<=m) update(L,R,c,lson); if(R>m) update(L,R,c,rson); pushup(rt); } int main() { int T; scanf("%d",&T); for(int t=1;t<=T;t++) { int n,m; scanf("%d%d",&n,&m); build(1,n,1); for(int i=0;i
             
              

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇TCO14 1B L3: EagleInZoo, dp,tr.. 下一篇SPOJ 1043 Can you answer these ..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: