Always_Remember_It @ 2022-08-08 14:23:35
@Obito 的题解中 query函数中int mid=(tree[k].l+tree[k].r)>>1; 为什么不是int mid=(lt+rt)>>1?
by Always_Remember_It @ 2022-08-08 14:24:07
https://www.luogu.com.cn/blog/41302/solution-p4513
by Fast_IO @ 2022-08-08 14:28:37
请先了解线段树
by muyang_233 @ 2022-08-08 14:28:40
其 lt
rt
并非当前线段树节点对应区间,而是要查询的区间。
by Fast_IO @ 2022-08-08 14:31:06
@zswmb 要按你这样改,递归出口在哪???
by Always_Remember_It @ 2022-08-08 14:38:12
int mid=(lt+rt)>>1; if(lt<=mid){ a=query(k2,lt,mid); ans.sum+=a.sum; } if(rt>=mid+1){ b=query(k2+1,mid+1,rt); ans.sum+=b.sum; }
by Always_Remember_It @ 2022-08-08 14:38:49
@muyang_233 @Fast_IO 那能否改成这样
by Fast_IO @ 2022-08-08 14:46:48
@zswmb 你查询端点变了线段树不就乱了。
by Always_Remember_It @ 2022-08-08 15:03:07
@Fast_IO 那请问为什么我线段树1的模板里的query函数写int mid=(l+r)/2能过啊
by Always_Remember_It @ 2022-08-08 15:04:10
@Fast_IO https://www.luogu.com.cn/record/64602300
by Always_Remember_It @ 2022-08-08 15:04:30
@Fast_IO 请问二者的区别?