做题记录 25.10.25
\(\textcolor{blue}\odot\) P13392 [GCJ 2010 #1A] Number Game
令 \(f(a,b)\) 表示 \((a,b)\) 是否先手必胜,则 \(f(a,b)=\begin{cases}1&a\ge 2b\lor b\ge 2a\\ f(a-b,b) &a<2b\land b<2a\land a>b\\ f(a,b-a) & a<2b\land b<2a\land a\le b\\ \end{cases}\)
可证 \(f(a,b)=\left[\max\left(\frac ab,\frac ba\right)>\frac{1+\sqrt 5}2\right]\)
统计答案是容易的,复杂度 \(O(\sum (b_2-b_1+a_2-a_1))\)
\(\textcolor{purple}\odot\) P12499 「DLESS-1」Life Lies in Movement
由于
\[\begin{aligned}
&\frac 1n \sum_{x=1}^n f(x,u,v) \ge \frac 12 \text{dis}(u,v)+k\\
\iff &2\sum_{x=1}^n f(x,u,v) \ge n\text{dis}(u,v)+2nk\\
\iff &2\sum_{x=1}^n f(x,u,v) - n\text{dis}(u,v) \ge 2nk\\
\iff &2\sum_{x=1}^n f(x,u,v) - \sum_{x=1}^n (f(x,u,v)+f(x,v,u)) \ge 2nk\\
\iff &\sum_{x=1}^n (f(x,u,v)-f(x,v,u)) \ge 2nk\\
\iff &\sum_{x=1}^n \text{dis}(x,v) - \sum_{x=1}^n \text{dis}(x,u) \ge 2nk\\
\end{aligned}
\]
令 \(s_i=\sum_{x=1}^n \text{dis}(x,i)\),容易 \(O(n)\) 换根 \(dp\) 求出,则等价于统计 \(s_v-s_u\ge 2nk\) 的 \((u,v)\) 数量,容易做到 \(O(n\log n)\)
总时间复杂度 \(O(\sum n\log n)\)

浙公网安备 33010602011771号