专栏文章

Solution to CF1992G Ultra-Meow

CF1992G题解参与者 2已保存评论 1

文章操作

快速查看文章及其快照的属性,并进行相关操作。

当前评论
1 条
当前快照
1 份
快照标识符
@mingow5a
此快照首次捕获于
2025/12/02 02:07
3 个月前
此快照最后确认于
2025/12/02 02:07
3 个月前
查看原文
Let MEX(S,k)\textrm{MEX}(S, k) be the kk-th positive integer in ascending order that is not present in SS.
Denote MEOW(a)\textrm{MEOW}(a) as the sum of MEX(b,b+1)\textrm{MEX}(b, |b| + 1) over all distinct subsets bb of array aa.
Given an array aa of length nn, consisting of 1,2,,n1,2,\dots, n. Determine the value of MEOW(a)\textrm{MEOW}(a).
1n50001\le n \le 5000.
Consider a subset bb of array aa. Assume that the maximum value in bb is mm, and there are exactly xx numbers <m< m that are not present in bb. We have
mx=bMEX(b,b+1)=MEX(b,mx+1)\begin{gather*} m - x = |b| \\ \textrm{MEX}(b, |b| + 1) = \textrm{MEX}(b, m - x + 1) \end{gather*}
For convenience, let T=MEX(b,mx+1)T = \operatorname{MEX}(b, m - x + 1). We now distinguish between two cases.
If b+1=mx+1>x|b| + 1 = m - x + 1 > x, i.e. m2xm \ge 2x, then T>mT > m holds, which implies that
T=m+b+1x=2m2x+1\begin{aligned} T = m + |b| + 1 - x = 2m - 2x + 1 \end{aligned}
Thus, for fixed mm and xx, their contribution to the final answer is
(2m2x+1)(m1x) (2m - 2x + 1)\binom{m - 1}{x}
Otherwise, m<2xm < 2x, and T<mT < m holds.
Since TT is undetermined, we can simply enumerate all possible values of TT from 11 to m1m - 1.
Consider the current TT, which is the (mx+1)(m-x+1)-th integer that is not present. Hence, there are mxm-x integers [1,T)\in [1, T) and 2xm12x-m-1 integers (T,m)\in (T, m) which are not present.
Thus, for fixed mm and xx, their contribution to the final answer is
T=1m1T(T1mx)(m1T2xm1)=T=1m1(mx+1)(Tmx+1)(m1T2xm1)=(mx+1)(mx+1)\begin{aligned} &\sum_{T=1}^{m-1}T\binom{T-1}{m - x}\binom{m - 1 - T}{2x-m-1}\\ = &\sum_{T=1}^{m-1}(m-x+1)\binom{T}{m-x+1}\binom{m-1-T}{2x-m-1}\\ = &(m-x+1)\binom{m}{x + 1} \end{aligned}
where the combinatorial identity
k=0n(ka)(nkb)=(n+1a+b+1)\sum_{k=0}^n\binom{k}{a}\binom{n-k}{b} = \binom{n+1}{a+b+1}
is applied.
Proof.
k=0n(ka)(nkb)=k=0n(kka)(nkb)=k=0n(1)ka(a1ka)(1)nkb(b1nkb)=(1)nabk=0n(a1ka)(b1nkb)=(1)nab(ab2nab)=(n+1nab)=(n+1a+b+1)\begin{aligned} &\sum_{k=0}^n \binom{k}{a}\binom{n-k}{b} \\ =& \sum_{k=0}^n \binom{k}{k-a}\binom{n-k}{b} \\ =& \sum_{k=0}^n (-1)^{k-a}\binom{-a-1}{k-a}(-1)^{n-k-b}\binom{-b-1}{n-k-b} \\ =& (-1)^{n-a-b}\sum_{k=0}^n \binom{-a-1}{k-a}\binom{-b-1}{n-k-b} \\ =& (-1)^{n-a-b}\binom{-a-b-2}{n-a-b} \\ =& \binom{n+1}{n-a-b} \\ =& \binom{n+1}{a+b+1} \\ \blacksquare \end{aligned}
We can obtain the answer by iterating mm and xx, and combining the contributions from the two cases.
The final answer is
i=1n(j=0i2(2i2j+1)(i1j)+j=i2+1i1(ij+1)(ij+1))\boxed{\sum_{i=1}^n\left( \sum_{j=0}^{\left\lfloor \frac{i}{2} \right\rfloor} (2i-2j+1)\binom{i-1}{j} + \sum_{j=\left\lfloor \frac{i}{2} \right\rfloor + 1}^{i-1}(i-j+1)\binom{i}{j+1} \right)}
Time complexity: Θ(n2)\Theta(n^2) per testcase.
Credit to MiniLongfor the proof part.

评论

1 条评论,欢迎与作者交流。

正在加载评论...