线段树区间合并就挺麻烦了,再套个树链就更加鬼畜,不过除了代码量大就没什么其他的了.. 一些细节:线段树每个结点用结构体保存,pushup等合并函数改成返回一个结构体,这样好写一些 struct Seg{ int lc,rc,tot; Seg(){lc=rc=-;tot=;} }; Seg seg[maxn<<];]; Seg pushup(Seg a,Seg b){ if(!a.tot)return b; if(!b.tot)return a; Seg res; res.lc=a.lc,res…