线段树的新写法

jys posted @ Feb 12, 2013 10:06:39 PM in 未分类 , 972 阅读

从此以后不再使用堆式写法。空间时间双重还写起来那么麻烦。

新写法和平衡树的写法比较接近。

 

namespace SGT
{
    int lc[NN],rc[NN],val[NN],p[NN],tot=0,lnk[MM];
    void build(int l,int r,int pa)
    {
        int now=++tot;p[now]=pa;
        if(l==r){lnk[l]=now;return;}
        lc[now]=tot+1;build(l,MID(l,r),now);
        rc[now]=tot+1;build(MID(l,r)+1,r,now);
    }
}

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter