做题记录 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)\)

代码

参考

posted @ 2025-10-26 06:36  Hstry  阅读(0)  评论(0)    收藏  举报