[噼昂!]FSYO

\[\color{red}{\text{校长者,真神人也,左马桶,右永神,会执利笔破邪炁,何人当之?}} \\ \begin{array}{|} \hline \color{pink}{\text{The principal is really a god}} \\ \color{pink}{\text{with a closestool on the left and Yongshen on the right}} \\ \color{pink}{\text{holding a sharp pen to pierce the truth}} \\ \color{pink}{\text{Who can resist him? }} \\ \hline \end{array} \\ \begin{array}{|} \hline \color{green}{\text{校長は本当に神であり、左側にトイレ、右側にヨンシェンがあり}} \\ \color{green}{\text{鋭いペンを持って真実を突き刺している。誰が彼に抵抗できるだろうか? }} \\ \hline \end{array} \\ \begin{array}{|} \hline \color{lightblue}{\text{Le principal est vraiment un dieu}} \\ \color{lightblue}{\text{avec des toilettes à gauche et Yongshen à droite}} \\ \color{lightblue}{\text{tenant un stylo pointu pour percer la vérité}} \\ \color{lightblue}{\text{Qui peut lui résister ? }} \\ \hline \end{array} \\ \begin{array}{|} \hline \color{purple}{\text{Der Direktor ist wirklich ein Gott}} \\ \color{purple}{\text{mit einer Toilette links und Yongshen rechts}} \\ \color{purple}{\text{der einen spitzen Stift hält}} \\ \color{purple}{\text{um die Wahrheit zu durchdringen.}} \\ \color{purple}{\text{Wer kann ihm widerstehen? }} \\ \hline \end{array} \\ \begin{array}{|} \hline \color{cyan}{\text{Principalis deus est, Yongshen a dextris cum latrina}} \\ \color{cyan}{\text{acuto stylo ad perforandum veritatem: quis resistet ei? }} \\ \hline \end{array} \\ \color{red}{\text{对曰:“无人,狗欲当之,还请赐教!”}} \\ \newcommand\bra[1]{\left({#1}\right)} \newcommand\Bra[1]{\left\{{#1}\right\}} \newcommand\dx[0]{\text{dx}} \newcommand\string[2]{\genfrac{\{}{\}}{0pt}{}{#1}{#2}} \newcommand\down[2]{{#1}^{\underline{#2}}} \newcommand\ddiv[2]{\left\lfloor\frac{#1}{#2}\right\rfloor} \newcommand\udiv[2]{\left\lceil\frac{#1}{#2}\right\rceil} \newcommand\lcm[0]{\operatorname{lcm}} \newcommand\set[1]{\left\{{#1}\right\}} \newcommand\ceil[1]{\left\lceil{#1}\right\rceil} \newcommand\floor[1]{\left\lfloor{#1}\right\rfloor} \]


我愿称这场比赛为降维打击......

Problem A. F

给两个数列 \(a_i,b_i\),你要找到一个排列 \(\sigma\),使得每个 \(a_i\oplus b_{\sigma_i}=x\) 都相等。你要输出所有可能的 \(x\).

保证 \(n\le 2000,0\le a_i,b_i\le 10^9\).

感觉曾经在哪里做过......我们可以直接枚举 \(a_1\) 究竟是跟谁匹配,得到这个可能的 \(x\) 之后检查剩下的 \(a_i\) 是否都能找到自己的配对对象。使用 map 让这个题复杂度达到了 \(\mathcal O(n^2\log n)\).

Problem B. S

\(n\) 个球,每个球有 \(\tt R,G,Y\) 三种颜色,现在小 \(\sf F\) 觉得如果有两个相邻的球颜色相同很丑。他每次可以交换两个球,问至少交换多少次才能不丑。如果无法不丑输出 \(-1\).

保证 \(n\le 400\).

真的被降智了......显然每种颜色的球相对位置不会发生改变,如果我们知道了最终的序列样子,那么交换次数便也可以被确定。

不妨考虑 \(\rm DP\),在 \(\rm DP\) 状态中将当前与序列样子有关的状态记录下来,设 \(f(n,i,j,0|1|2)\) 表示当前在位置 \(n\),红色使用了 \(i\),绿色使用了 \(j\),当前位置填色 \(0|1|2\) 的最小交换次数,于是就可以进行转移,转移的花费实际上就是逆序对的数量,记录一下颜色的位置即可。

注意,空间不够,需要滚动一维,时间复杂度 \(\mathcal O(n^3)\).

Problem C. Y

\(n\) 个人站成一个圈,每个人有 \(a_i\) 个球,下面要进行一次操作:

  • 每个人把一些它的球交给它左边的人,所有人同时进行。

在进行完该操作之后,每个人有 \(b_i\) 个球,记这个序列为 \(B\). 对于每种 \(B\),它的价值为 \(\prod b_i\).

对于所有可能的 \(B\),你要计算它们的价值和,对 \(10^9 + 7\) 取模。

这是 \(\rm Atcoder\) 的原题,传送门 to Atcoder. 可以发现除了模数不一样,其他的都差不多。

\(c_i\) 表示第 \(i\) 个人往后面传了 \(c_i\) 个球,不难发现,若 \(\forall c_i>0\),那么我们可以整体减去 \(1\),因为这不会对最终我们得到的 \(B\) 产生影响,往复下去,不难发现最终一定会出现 \(c_i=0\) 的位置,即表示这个人并没有向后传球,于是,我们可以枚举这个不传球的懒家伙,从他开始破环为链。

可以设计状态 \(f(i,j)\) 表示第 \(i\) 个人向后传了 \(j(j>0)\) 个球的方案数。那么,存在转移

\[f(i,j)=\sum_{k=1}^{a_{i-1}}(a_i-j+k)\times f(i-1,k) \]

对于这个转移,我们只需要维护 \(\sum_{j}f(i,j)\) 以及 \(\sum_{j}j\times f(i,j)\).

我们尝试维护这俩东西,若

\[s_i^{[1]}\overset\Delta=\sum_{j=1}^{a_i} f(i,j) \\ s_i^{[2]}\overset\Delta=\sum_{j=1}^{a_i}j\times f(i,j) \]

\[\begin{aligned} s_i^{[1]}&=\sum_{j=1}^{a_i}(a_i-j+k)\times f(i-1,k) \\ &=\bra{a_i^2-2\mathrm{sum}(a_i)}s_{i-1}^{[1]}+a_is_{i-1}^{[2]} \\ s_i^{[2]}&=\sum_{j=1}^{a_i}(a_i-j+k)\times j\times f(i-1,k) \\ &=(a_i\times \mathrm{sum}(a_i)-\mathrm{squa}(a_i))s_{i-1}^{[1]}+\mathrm{sum}(a_i)\times s_{i-1}^{[2]} \end{aligned} \]

于是我们可以把它搬到矩阵上面:

\[\begin{pmatrix} s_{i-1}^{[1]}&s_{i-1}^{[2]} \end{pmatrix} \times \begin{pmatrix} \bra{a_i^2-2\mathrm{sum}(a_i)} & a_i\times \mathrm{sum}(a_i)-\mathrm{squa}(a_i)\\ a_i & \mathrm{sum}(a_i) \end{pmatrix} = \begin{pmatrix} s_{i}^{[1]}&s_{i}^{[2]} \end{pmatrix} \]

我们可以维护一个转移矩阵的前后缀乘积,可以做到枚举开始点 \(\mathcal O(n)\),获得最终转移值 \(\mathcal O(1)\) 的复杂度。

当然,你也可以使用 \(\rm Atcoder\) 上给出的容斥,个人感觉后者更好,并且常数更小。

posted @ 2021-10-17 22:46  Arextre  阅读(106)  评论(0编辑  收藏  举报