P1485火枪打怪(题解)
Link.
PS.
此题第一眼就可以看出是二分答案我看了标签QwQ
Solution.
最难的是二分的$\texttt{check}$函数如何写。
首先因为子弹的威力是定值,所以每一个子弹的溅射范围是一样的,事先算出溅射范围。
$\texttt{p-(i-j)}\times\texttt{(i-j)}=\texttt{p-i}^\texttt{2}+\texttt{2}\times\texttt{i}\times\texttt{j+j}^\texttt{2}$
这个式子中,$\texttt{i}^\texttt{2}$、$\texttt{2}\times\texttt{i}\times\texttt{j}$、$\texttt{j}^\texttt{2}$ 都是可以维护的。
于是我们维护$\texttt{i}^\texttt{2}$之和,$\texttt{2}\times\texttt{i}$之和,$\texttt{1}$之和。
在加入时可以临时乘上$\texttt{j}$的次方次幂。
Coding.
1 |
|