正文
增加 19 行删除 1 行
193 行未改动全部展开19419519619719819920020120220320420520620720820969 行未改动279280281282283284285286145 行未改动全部展开193 行未改动全部展开每个节点 $i$ 管辖一段长度为 $\text{lowbit}(i)$ 的区间。用**彩色块**标出来:$$\begin{array}{c|cccccccc}i & \textcolor{red}{1} & \textcolor{orange}{2} & \textcolor{yellow}{3} & \textcolor{green}{4} & \textcolor{cyan}{5} & \textcolor{blue}{6} & \textcolor{purple}{7} & \textcolor{gray}{8} \\\hline\text{lowbit}(i) & 1 & 2 & 1 & 4 & 1 & 2 & 1 & 8 \\\hline\text{管辖区间} & [1,1] & [1,2] & [3,3] & [1,4] & [5,5] & [5,6] & [7,7] & [1,8] \\\end{array}$$用箭头画一次**前缀查询** $\text{query}(6)$ 的跳跃路径:$$6 \xrightarrow{-\text{lowbit}(6)=2} 4 \xrightarrow{-\text{lowbit}(4)=4} 069 行未改动\end{aligned}}$$原理一句话:**从高位到低位试探,如果跳过去之后累计还不够 $k$,就跳**。---145 行未改动全部展开193 行未改动全部展开19419519619719819920020120220320420520620720820921021121221321421521669 行未改动286287288289290291292293294295296297298299300301302303304145 行未改动全部展开193 行未改动全部展开每个节点 $i$ 管辖一段长度为 $\text{lowbit}(i)$ 的区间。用**彩色块**标出来:$$\begin{array}{c|cccccccc}i & \textcolor{red}{1} & \textcolor{teal}{2} & \textcolor{red}{3} & \textcolor{blue}{4} & \textcolor{red}{5} & \textcolor{teal}{6} & \textcolor{red}{7} & \textcolor{purple}{8} \\\hline\text{lowbit}(i) & 1 & 2 & 1 & 4 & 1 & 2 & 1 & 8 \\\hline\text{管辖区间} & [1,1] & [1,2] & [3,3] & [1,4] & [5,5] & [5,6] & [7,7] & [1,8] \\\end{array}$$| $\textcolor{purple}{tr_8}$ | < | < | < | < | < | < | < || :------------------------: | :-: | :---------------------: | :-: | :----------------------: | :-: | :---------------------: | :-: || $\textcolor{blue}{tr_4}$ | < | < | < | | < | < | < || $\textcolor{teal}{tr_2}$ | < | | < | $\textcolor{teal}{tr_6}$ | < | | < || $\textcolor{red}{tr_1}$ | | $\textcolor{red}{tr_3}$ | | $\textcolor{red}{tr_5}$ | | $\textcolor{red}{tr_7}$ | |用箭头画一次**前缀查询** $\text{query}(6)$ 的跳跃路径:$$6 \xrightarrow{-\text{lowbit}(6)=2} 4 \xrightarrow{-\text{lowbit}(4)=4} 069 行未改动\end{aligned}}$$> Python:```pythondef find_kth(k):p,step=0,int(log2(m))>>1while step>0:if p+step<=m and tree[p+step]<k:k-=tree[p+step]p+=stepstep/=2```原理一句话:**从高位到低位试探,如果跳过去之后累计还不够 $k$,就跳**。---145 行未改动全部展开