if(l <= Md) res += qry(p<<1, l, r); if(r > Md) res += qry(p<<1|1, Md + 1, r);//应该是qry(p<<1|1, l, r)
下传的区间不要写错了