2024.7 #3 我从不怕摔倒 拼命向前跑 把每一天过好 和大家拥抱

我从不怕摔倒
拼命向前跑
把每一天过好
和大家拥抱----乐正绫《万圣街》


T1. P5572 [CmdOI2019] 简单的数论题

和毒瘤之神的考验类似的毒瘤题。

首先先化简原式:

\[\begin{array}{l} \sum^n_{i = 1} \sum^m_{j = 1} \varphi(\dfrac{{\rm lcm}(i,j)}{\gcd(i,j)}) = \sum^n_{i = 1}\sum^m_{j = 1} \varphi(\dfrac{i \times j}{\gcd(i,j)^2})\\= \sum^n_{d = 1}\sum^{n}_{i = 1}\sum^m_{j = 1} \varphi(\dfrac{i \times j}{d^2})[\gcd(i,j) == d]\\= \sum^n_{d = 1}\sum^{\lfloor \frac{n}{d} \rfloor}_{i = 1}\sum^{\lfloor \frac{m}{d} \rfloor}_{j = 1} \varphi(i \times j)[\gcd(i,j) == 1]\\= \sum^n_{d = 1}\sum^{\lfloor \frac{n}{d} \rfloor}_{i = 1}\sum^{\lfloor \frac{m}{d} \rfloor}_{j = 1} \varphi(i) \times \varphi(j)[\gcd(i,j) == 1]\\= \sum^n_{d = 1}\sum^{\lfloor \frac{n}{d} \rfloor}_{i = 1}\sum^{\lfloor \frac{m}{d} \rfloor}_{j = 1} \varphi(i) \times \varphi(j) \sum_{p \mid \gcd(i,j)} \mu(p)\\= \sum^n_{d = 1}\sum^{\lfloor \frac{n}{d} \rfloor}_{p = 1} \mu(p) \sum^{\lfloor \frac{n}{d} \rfloor}_{i = 1} \sum^{\lfloor \frac{m}{d} \rfloor}_{j=1} \mu(i) \mu(j) [p \mid i] [p \mid j] \\= \sum^n_{d = 1}\sum^{\lfloor \frac{d}{n} \rfloor}_{p = 1} \mu(p) \sum^{\lfloor \frac{n}{pd} \rfloor}_{i = 1} \varphi(ip) \sum^{\lfloor \frac{m}{pd} \rfloor}_{j = 1} \varphi(jp)\\= \sum^n_{T = 1} \sum_{p | T} \mu(p) \sum^{\lfloor \frac{n}{T} \rfloor}_{i = 1} \mu(ip) \sum^{\lfloor \frac{m}{T} \rfloor}_{j = 1} \varphi(jp) \end{array} \]

然后我们设 \(G(x,y) = \sum^x_{i = 1} \varphi(iy)\)。那么原式子就变为 \(\sum_{T = 1}^n \sum_{p | T} \mu(p) G(\lfloor \frac{n}{T} \rfloor,p) G(\lfloor \frac{m}{T} \rfloor,p)\)

然后我们定义 \(H(x,y,z) = \sum_{T = 1}^z \sum_{p | T} \mu(p) G(x,p) G(y,p)\)

接着我们就可以用毒瘤之神的考验的套路了。用根号分支来求 \(H\),具体的我们设置一个阈值 \(B\),将所有 \(\le B\)\(H\) 都提前预处理出来,然后对于 \(\ge B\) 的部分,我们可以在查询时利用整除分块计算。


T2. P3911 最小公倍数之和

又是推式子题,好欸好欸好欸!虽然说大多数步骤都是类似的,但是还是有许多细节。

首先问们定义 \(c_i\) 表示 \(i\) 的出现次数,\(n\) 为最大值。那么就有:

\[\begin{array}{l} \sum^n_{i = 1} \sum^m_{j = 1}c_i \times c_j \times \rm{lcm}(i,j)\\= \sum^n_{i = 1} \sum^m_{j = 1}c_i \times c_j \times \dfrac{i \times j}{\gcd(i,j)}\\= \sum^k_{i = 1} \sum^n_{i = 1} \sum^m_{j = 1} c_i \times c_j \times \dfrac{i \times j}{k}[\gcd(i,j) == k]\\= \sum^k_{i = 1} \sum^{\lfloor \frac{n}{k} \rfloor}_{i = 1} \sum^{\lfloor \frac{m}{k} \rfloor}_{j = 1} c_{ik} \times c_{jk} \times i \times j \times k[\gcd(i,j) == 1]\\= \sum^k_{i = 1} \sum^{\lfloor \frac{n}{k} \rfloor}_{i = 1} \sum^{\lfloor \frac{m}{k} \rfloor}_{j = 1} \sum_{d \mid \gcd(i,j)} \mu(d) c_{ik} \times c_{jk} \times i \times j \times k\\= \sum^k_{i = 1}\sum^n_{kd = 1}\mu(d) \times d^2 \sum^{\lfloor \frac{n}{kd} \rfloor}_{i = 1}\sum^{\lfloor \frac{m}{kd} \rfloor}_{j = 1}c_{ikd} \times c_{jkd} \times i \times j \times k\\= \sum^n_{T = 1}T(\sum_{d|T} \mu(d) \times d) \sum^{\lfloor \frac{n}{T} \rfloor}_{i = 1}\sum^{\lfloor \frac{m}{T} \rfloor}_{j = 1}c_{iT} \times c_{jT} \times i \times j\\= \sum^n_{T = 1}T(\sum_{d|T} \mu(d) \times d) (\sum^{\lfloor \frac{n}{T} \rfloor}_{i = 1} c_{iT} \times i)^2 \end{array} \]

然后第一个预处理,后面的暴力算即可。


T3. CF911G Mass Change Queries

我们发现 \(a_i \le 100\),所以我们可以建出 \(100\) 棵线段树,然后我们只需要维护这些线段树即可。我们把所有 \(a_i = x\)\(i\) 放到第 \(x\) 个线段树上。

然后我们考虑怎么维护更改操作。其实就是把 \(x\) 线段树上在 \([l,r]\) 之间的点合并到 \(y\) 上,这样子对于所有在 \([l,r]\) 的点并且 \(a_i = x\)\(i\) 就全部移到了 \(y\) 线段树上。

posted @ 2024-07-22 17:14  sqrtqwq  阅读(3)  评论(1编辑  收藏  举报