做题记录 25.8.1
[2025“钉耙编程”中国大学生算法设计暑期联赛(5) 1005] 四角洲行动
令 \(a,b,c,d\) 为实际选择的 \(1\times 1,1\times 2,1\times 3,2\times 2\) 的物品数量,\(A,B,C,D\) 为格子数量,则合法当且仅当
\[c\le C\\
d\le D\\
b\le B+(C-c)+2(D-d)\\
a\le A+B+2C+4D-2b-3c-4d\\
\]
因此枚举 \(c,d,b\),从而得到 \(a\) 的最大值,用 \(w_1(a)+w_2(b)+w_3(c)+w_4(d)\) 跟新答案,其中 \(w_i(j)\) 表示第 \(i\) 种物品选择 \(j\) 个的最大贡献,容易预处理
总时间复杂度 \(O(\sum (cd(b+c+d)+\sum k\log k))\)
[2025“钉耙编程”中国大学生算法设计暑期联赛(5) 1001] 一个更无聊的游戏
按 \(a\) 从小到大加入,维护连通块,并将这一过程建成重构树,则一次询问 \((u,x)\) 等价于找到重构树上 \(u\) 第一个祖先 \(u'\) 满足 \(a_{fa_{u'}}-s_{u'}>x\),其中 \(s\) 表示重构树中子树内 \(b\) 之和,\(fa\) 表示重构树上的父亲
倍增维护即可,时间复杂度 \(O((n+q)\log n)\)
[2025“钉耙编程”中国大学生算法设计暑期联赛(5) 1006] 支配游戏
考虑求出每个连通块的 \(\text{SG}\) 函数值,异或起来后得到最终答案
令 \(C_n\) 表示长度为 \(n\) 的环的 \(\text{SG}\) 函数值,令 \(L_{i,n}\) 表示长度为 \(n\) 的链,两端中有 \(i\) 个被支配且剩余点都没有被支配的 \(\text{SG}\) 函数值,则长度为 \(n\) 的链的 \(\text{SG}\) 函数值为 \(L_{0,n}\)
显然
\[C_n=\begin{cases}1&n=2\\ \text{mex}\{L_{2,n-1}\}&n\ge 3\end{cases}\\
L_{2,n}=\begin{cases}0&n\le 2\\ \text{mex}_{i=1}^{n}\{L_{2,i-1}\oplus L_{2,n-i}\}&n\ge 3\end{cases}\\
L_{1,n}=\begin{cases}0&n\le 1\\ \text{mex}_{i=1}^{n}\{L_{1,i-1}\oplus L_{2,n-i}\}&n\ge 2\end{cases}\\
L_{0,n}=\begin{cases}0&n\le 0\\ \text{mex}_{i=1}^{n}\{L_{1,i-1}\oplus L_{1,n-i}\}&n\ge 1\end{cases}\\
\]
打表可得
\[L_{2,n}=\begin{cases}0&n\le 2\\ \{2,3,0,1\}[n\bmod 4]&n\ge 3\end{cases}\\
L_{1,n}=\begin{cases}0&n\le 1\\ \{3,0,1,2\}[n\bmod 4]&n\ge 2\end{cases}\\
L_{0,n}=\begin{cases}2&n=3\\ \{0,1,1,3\}[n\bmod 4]&n\ne 3\end{cases}\\
C_n=\begin{cases}1&n=2\\ [n\equiv 3\pmod 4]&n\ge 3\end{cases}\\
\]
总时间复杂度 \(O(\sum n)\)

浙公网安备 33010602011771号