鱼的加强版题解
\(*\color{black}{+}\color{red}{\infty}\)
Consider how to solve this problem when we only have single-point modification.We have the following conclusions.(this part is premise conclusion) :
- Observation 1 :we only have \(O(n)\) ordered pairs \((l,r)\) that satisfy following conditions : \((\max\limits_{i=l+1}^{r-1}a_i)<\min(a_l,a_r)\) .
Lets \(l_i=\max\limits_{j<i,a_j>a_i}(j),r_i=\min\limits_{j>i,a_j>a_i}(j)\) .
Enumerate \((l,r)\) that \((l,r)\) is domination point pair
.Lets \(w\gets\operatorname{argmax}\limits_{i=l+1}^{r-1}(a_i)\) . It's easily to find that \(l=l_w,r=r_w\) .So let's be bolder.we have following conclusions:
- Observation 2 :Ordered pair \((l,r)\) that satisfy \((\max\limits_{i=l+1}^{r-1}a_i)<\min(a_l,a_r)\) Form a bijection with all \((l',r')\) ordered pairs that exist a \(x\) such that \(l_x=l',r_x=r'(1\le x\le n)\)
The prove is easy , so we skip it.
Next, consider a type of dominance point pair.If we have a ordered pair \((l,r)\) and a number \(i\) that \(i\in(l,r)\) , \((\sum\limits_{i=l+1}^{r-1}a_i)<\min(a_l,a_r)\) .We can consider that fish named \(i\) can't eat fish named in \([1,l]\) or \([r,n]\) .
So we have some conclusions:
-
Observation 3 :We only have \(O(n)\) of this kind of dominance point pair.
-
Observation 4 :for a query \([l,r]\) ,consider to set \(a_{l-1}\) and \(a_{r+1}\) to \(+\infty\) .(this is an emporary assignment, to be changed back after the operation is completed
),so the answer is \(r-l+1-ans\) ,Where \(ans\) is the size of area who covered by dominance point pairs.
Lets \(S_i=\sum\limits_{1\le j<i,(j,i)\ is \ dominance \ pair}\{j\}\) , \(T_i=\sum\limits_{i<j\le n,(i,j)\ is \ dominance \ pair}\{j\}\) 。
Then consider the changes to \(S\) and \(T\) in a single operation.We have the following conclusions:
- Observation 5 :For a modification to the interval $[l, r] $, only \(S_l, S_{l+1}\) and \(T _r\) may add new elements, while the other \(S_i\) and \(T_i\) may only delete some elements on the original basis.
Consider how to find these elements.Lets \(b_i\gets a_i-a_{i-1},d_i=a_i-a_{i+1}\) .It is easy to observe that each operation modifies the \(b\) and \(d\) arrays by adding a number (possibly \(0\) or a negative number) to a interval.
Now we need to implement the function of refactoring \(S_i\) and \(T_i\) .
We only consider refactoring Si.It is easy to find that we need to implement \(O (\log n)\) to find the maximum \(i\) that satisfies \(a_i>(\sum\limits_{j=i+1}^{x}a_j )\) ,
Define \(s\) as the internal \(\sum a\) of the previous dominating point pair
.Then we have following conclusions:
- Observation 6 :The problem can be transformed into finding the maximum \(i\) that satisfies \(a_i>s\) .Since \(s\) becomes \(2s+\delta(\delta\ge 0)\) every time \(a_i>s\) is found, the maximum number of \(O (\log V)\) rounds can be found.
This condition is not very simple, we need to strengthen it, so we have following conclusions:
- Observation 6 :The problem can be transformed into finding the maximum \(i\) that satisfies \(a_i-a_{i+1}>s\) .Since \(s\) becomes \(2s+\delta(\delta\ge 0)\) every time \(a_i>s\) is found, the maximum number of \(O (\log V)\) rounds can be found.
Note that \(a_i-a_{i+1}=d_i\), and each modification has an impact on \(d\) in the form of adding or subtracting a number in the interval. Therefore, we can perform binary partitioning on the line segment tree, which can reconstruct \(S _i\) or \(T_i\) by $O(n\log V\log n) $.
Therefore, we only need to find the appearance and departure time of each dominant point pair now, and consider dynamic maintenance.
So we can categorize and discuss the impact of interval modification on the dominance point pair $[l,r] $ , assuming that the modified interval is \([L',R']\) .
-
When $l \le L'\le R' \le r $ , it is equivalent to subtracting a number from the weights of these $[l, r] $. We have the conclusion that:
-
Observation 8 :We can quickly find these \((l, r)\) based on Observation 6 and Observation 7, and brute force calculate the impact, which can be processed by \(O (n \log n \log V)\) .
-
When \(l\le L'\le r\le R'\) , it is equivalent to subtracting a number from the weights of these $[l, r] $. We have the conclusion that:
-
Observation 9 :We can quickly find these \((l, r)\) based on Observation 6 and Observation 7, and brute force calculate the impact, which can be processed by \(O (n \log n \log V)\) .
The situation of \(L'\le l\) is still the same, but there is a special case:
- When $L '\le l \le r \le R' $ , it is not possible to quickly find \((l, r)\) that meets the requirements. This part can be achieved by using binary segmentation on the line segment tree and offline processing to achieve $O (n \log n \log V) $ .
Then implement a scanning line method to achieve AC.
Therefore, we solved this problem within the complexity of $O (n \log n \log V) $ .
We just wrote the solution for U646757,Let's start the abnormal mode below.
For parallel universes in the \(m\) dimension, we have the following conclusion:
Since eating fish requires strict partial order in all dimensions, assuming there is a \((s_1,\cdots,s_m)\) fish, we consider finding the first \(>s_i\) fish for each dimension. We define the property of a fish as \(S \gets \prod \limits_ {1\le i\le m}(s_i)\), so \(S\) will not exceed \(V ^ m\) .
-
Observation 10 :When \(S\) eats a fish with \(>s_i\) in a certain dimension, $S \gets 2S+\delta (\delta\ge 0) $ .Which means that the maximum number of such fish eaten is on the order of $O (m \log V) $ .
-
Observation 11 : The conclusion derived from Observation 10 states that the number of dominance pair including a single point is on the order of \(O(m \log V)\) .
-
Observation 12 : A \((l, r)\) is a dominating point pair if and only if it is also a dominating point pair in one dimension, or if it satisfies $a_{l-1}>\sum\limits_ {i=l} ^ r (a_i)>a_ {r+1} $ or $a_ {l-1}<\sum \limits_ {i=l} ^ r (a_i)<a_ {r+1} $ in one dimension. Prove is easy,so we skip it.
-
Observation 13: The total number of global dominating point pairs is on the order of $O(nm \log V) $.
Proof: Derived from Observation 12.
Next, let's consider the problem of polynomials.Lets \(f(x)\gets \max\limits_{i^x\ge (\sum\limits_{j=1}^{i-1} j^x)}(i)+1\) .
-Observation 14: Only \(S_{l},\cdots,S_{l+f(k)-1}\) and \(T_r,\cdots,T_{r-f(k)+1}\) needs to be refactored each time, while the rest involves deleting elements from the original foundation.
- Observation 15 : Lets \(g(x)\gets x^k\) , \(c(x)=g(x)-g(x-1)(x\ge 1)\) ,So \(c(x)\) is showing an increasing trend, that is, the growth rate of \(g\) is getting faster and faster.
Proof: Considering factorization, \(a^m-b^m=(a-b)(\sum\limits_{i=0}^{m-1} a^ib^{m-1-i})\) , the right-hand side is clearly increasing.
- Observation 16 :Lets \(h(x)=\frac{(\sum\limits_{i=1}^{x-1}i^m)}{x^m}\) ,Then \(\forall x,h(x)\le h(x+1)\) 。
Proof:
Define \(S_n=\sum\limits_{i=1}^{n-1}\{\frac{i}{n}\}\), then obviously the conclusion holds when the \(S_n\)'s ranking is less than \(S_{n+1}\), so obviously $S_n<S_{n+1} $, the proof is complete.
- Observation 17 : If \(x^m<(\sum\limits_{i=1}^{x-1}i^m)\), then \((x+1)^m<(\sum\limits_{i=1}^x i^m)\) .
Proof: Derived from Observation 16.
- Observation 18 :\(f(x)\le 2^x+2\) 。
Proof:Consider scaling, regarding mean symmetry
,\((\sum\limits_{i=1}^{2^x+1}i^x)\ge(2^{x-1}+1)^x(2^x+1)=(2^x+2)^x+(2^{x-1}+1)^x\) .
- Observation 19 :\(f(x)\) is on the scale of \(O(m\log m)\).
Proof: Because every time a number greater than itself is added, \(\log_2(\operatorname{sum})\) will always be at least \(+1\) , the inequality \(m\log x\le x\) can be formulated, and \(x\) can be solved within the order of $O(m\log m) $ .
The next step is the original algorithm. Note that the focus is still on finding the dominant point pairs.Lets \(c_{i,j}\gets \max(c_{i,j-1},0)-\max(c_{i-j,j-1},0)\) , \(c_{i,0}\gets a_i\) .
So we have following conclusions:
- Observation 20 : A necessary but insufficient condition for \(a_i>(\sum\limits_{j=i+1}^{T}a_j)+s\) is \(c_{i,k}>s\) .And B is an sufficient and unnecessary condition for A.Therefore, find \(i\) where \(c_{i,k}>s\) can fit in this problem.
The following is a mandatory online situation with $k\ge 2 $, where \(k=1\), simply use 'Observation 20'.
Lets \(d_{i,j}\gets d_{i,j-1}-d_{i-2^{j-1},j-1}\) , \(d_{i,0}\gets a_i\) 。
Then we have following conclusions:
- Observation 21 : \(d_{i,j}\gets\sum\limits_{k=0}^{2^j-1}(-1)^{\operatorname{popcount}(k)}a_{i-k}\) 。
Proving to consider induction, omitted.
- Observation 22 :when \(d_{i,j}>s\) ,we have \(\max\limits_{k=i-2^j+1}^i(a_k)\ge\frac{s}{2^j}\) .
The prove is easy,so we skip it.
So notice that every time you search for the first \(d_{i,k}>s\)'s \(i\), \(s\) will change to \((1+\frac{1}{2^k})s+\delta(\delta\ge 0)\).
- Observation 23 : Lets \(g(x)=\log_{1+\frac{1}{x}}(2)\) ,Then \(g(x)\le f(x)\) 。
Just prove to consider the difference.
So the overall complexity is \(O(nm^24^kk^2\log k\log n\log V)\). Once completed, the complexity of the brute force algorithm is \(O(nq(k+m\log V))\).
刚才忽略了我们的支配点对消亡时间的处理,其形如 \(d\) 维凸包,下面我们有结论:
- Observation 24 :构建一个 \(n\) 点 \(d\) 维度的凸包需要复杂度 \(O(n^{\lceil\frac{d}{2}\rceil})\) 。
那么接下来我们就可以应用一个分块,总复杂度为 \(O(nm^24^kk^2\log k\log n\log V+n^{2-\frac{1}{\lceil\frac{k}{2}\rceil+1}}(\log V)^\frac{1}{\lceil\frac{k}{2}\rceil+1})\)
下面是我们非离线的版本的一个简单的做法:
考虑令 \(b_i\gets \lfloor\log_2(a_i)\rfloor\) ,那么随着时间的推移, \(b_i\) 显然单调不降,因此可以预处理出来对于每个 \(i\) ,它的 \(b_i=v\) 的时间区间 \([L_{i,v},R_{i,v}]\) ,这部分的复杂度是 \(O(n\log n\log V)\) 的。
然后每次找支配点对的时候就找到 \(b_i\ge \lfloor\log_2(s)\rfloor\) 的即可,我们有结论:
- Observation 25 : 这种找法的复杂度可以省 \(O(2^kk)\) 倍。
那么整体的复杂度便为 \(O(nm^22^kk\log k\log n\log V)\) .
下面是区间赋值成多项式版本的一个简单的做法:
还是考虑令 \(b_i\gets\lfloor\log_2(a_i)\rfloor\) ,那么我们有结论:
-
Observation 26 : 每次赋值操作结束后,赋值区间内的 \(b_i\) 单调不降.
-
Observation 27 : 每次结束赋值操作后,需要对包含 \([l,r]\) 的支配点对和 \(S_{[l,l+f(k)-1]},S_{[r-f(k)+1,r]}\) 进行重构,其他的部分,如果存在一个支配点对和 \([l,r]\) 的交集部分大小大于 \(f(k)\) ,那么该支配点对会被删除.
那么整体的复杂度便为 \(O(nm^22^kk\log k\log n\log V+n^{2-\frac{1}{\lceil\frac{k}{2}\rceil+1}}(\log V)^\frac{1}{\lceil\frac{k}{2}\rceil+1})\) .
下面是一些神秘的结论和思维方式:
- Observation 28 : 假设我们把所有具备包含关系的支配点对连成一个图,那么这个图是一棵树,而且可以考虑在这棵树上做 DSU on tree.
下面是【大鱼吃小鱼】加入进来之后的几个结论和做法:
对于一个区间 \([l,r]\) ,如果 \((\sum\limits_{i=l}^r a_i)<k'\) ,那么称这个区间为小鱼区间,否则称它为大鱼区间。
对于一个区间 \([l,r]\) ,如果 \((\sum\limits_{i=l}^r a_i)>k'\) 且 \((\sum\limits_{i=l}^r a_i)<\min(a_{l-1},a_{r+1})+k'\) ,那么称该区间为大鱼支配区间。
-
Observation 29 : 两个大鱼支配区间的交集要么为空,否则一定是小鱼区间。
-
Observation 30 : 一个数组的大鱼支配区间的数量为 \(O(n)\) 量级。
-
Observation 31 : 包含一个点的大鱼支配区间的数量为 \(O(k\log V)\) 量级。
-
Observation 32 :我们注意到包含一个点的内部 \((\sum a)>k\times p\) 的本质不同支配点对的数量为 \(O(kp\log V)\) 量级。
那么本题可以在 \(O(nm^2k^38^k\log k\log n\log V)\) 的复杂度内完成。
下面称区间加一个多项式为 A 类操作,区间赋值为一个多项式是 B 类操作。
C 类操作:区间 \(a_i\gets\min(a_i,v)\) ,考虑题目中如果只有 C 类操作且允许离线的话,这题应该怎么做。
假设现在有一次 C 类的操作,操作的是 \([l,r]\) 这个区间,那么考虑重构和 \([l,r]\) 有交但不被 \([l,r]\) 完全包含的区间。剩下的部分我们有结论:
- Observation 33 :对于被 \([l,r]\) 包含的部分,不会产生新的支配点对,只会在旧有的支配点对基础上进行删除,而假设删除的支配点对的内部 \(\sum a=A\) ,那么只有 \(v\le A\) 时这个支配点对才会被删除。这个时候可以认为是在找到区间中 \(A\) 最大的点对,然后考虑是否删除它。
但是对于重构支配点对这一部分,我们仍然需要支持找到某个区间范围内第一个 \(>s\) 的数,考虑令 \(b_i\gets \lfloor\log_2(a_i)\rfloor\) ,然后找到第一个 \(>s\) 的数这个目标可以转为找到第一个 \(b_i\ge\lfloor\log_2(s)\rfloor\) 的数,然后 \(b_i\) 是随着操作的进行不断增长的。
因此可以考虑离线处理 \(b_i\) 的修改,然后就做完了。
D 类操作,区间 \(a_i\gets \max(a_i,v)\) ,考虑题目中如果只有 D 类操作且允许离线的话,这题应该怎么做。
假设现在有一次 D 类的操作,操作的是 \([l,r]\) 这个区间,那么考虑重构和 \([l,r]\) 有交但不被 \([l,r]\) 完全包含的区间。剩下的部分我们有结论:
- Observation 34 :对于被 \([l,r]\) 包含的部分,不会产生新的支配点对。
对于支配点对消亡时间的处理,我们可以应用 Segment-Beats 去解决,我们有结论:
- Observation 35 : Segment-Beats 的复杂度为 \(O(q\log n)\) 。
那么这部分的复杂度就是 \(O((n+q)\log^2 n\log V)\) 。
但是对于重构支配点对这一部分,我们仍然需要支持找到某个区间范围内第一个 \(>s\) 的数,考虑令 \(b_i\gets \lfloor\log_2(a_i)\rfloor\) ,然后找到第一个 \(>s\) 的数这个目标可以转为找到第一个 \(b_i\ge\lfloor\log_2(s)\rfloor\) 的数,然后 \(b_i\) 是随着操作的进行不断增长的。
因此可以考虑离线处理 \(b_i\) 的修改,然后就做完了。
E 类操作,区间 \(a_i\gets \lfloor\frac{a_i}{v}\rfloor\) 。
考虑如果只有这种操作怎么做,强制在线。
考虑这种操作当 \(v=1\) 时相当于不操作,否则定义 \(c_i\gets\lfloor\log_2(a_i)\rfloor\) 。
那么处理操作时,我们有如下的结论:
- Observation 36 : 如果有 \(x\) 个成功被除以 \(v\) 的 \(a_i\) ,那么 \(\sum(c_i)\) 至少减少 \(x\) 。
然后知道 \(\sum(c_i)\) 在 \(O(n\log V)\) 量级,那么可以考虑实现一个数据结构,能够找到区间的最大值和单点修改,接下来就是 P9530 了,复杂度是 \(O((n+q)\log n\log^2 V)\) 。
F 类操作,区间 \(a_i\gets a_iv\) ,令 \(inf=10^{18}\)
考虑如果只有这种操作怎么做,强制在线。
考虑这种操作当 \(v=1\) 时相当于不操作,否则定义 \(c_i\gets\lfloor\log_2(\frac{inf}{a_i})\rfloor\) 。
那么处理操作时,我们有如下的结论:
- Observation 37 : 如果有 \(x\) 个成功乘以 \(v\) 的 \(a_i\) ,那么 \(\sum(c_i)\) 至少减少 \(x\) 。
然后知道 \(\sum(c_i)\) 在 \(O(n\log V)\) 量级,那么可以考虑实现一个数据结构,能够找到区间的最大值和单点修改,接下来就是 P9530 了,复杂度是 \(O((n+q)\log n\log^2 V)\) 。
G 类操作,区间 \(a_i\gets a_i \& v\) 。
考虑如果只有这种操作怎么做,强制在线。
- Observation 38 :这种情况可以化为 \(O(n\log V)\) 次单点修改。
我们需要快速找到可以修改的元素,这部分可以利用线段树找到第一个 \(>x/<x\) 的数来快速处理。
做完了。
H 类操作,区间 \(a_i\gets a_i | v\) 。
考虑如果只有这种操作怎么做,强制在线。
- Observation 39 :这种情况可以化为 \(O(n\log V)\) 次单点修改。
我们需要快速找到可以修改的元素,这部分可以利用线段树找到第一个 \(>x/<x\) 的数来快速处理。
做完了。

浙公网安备 33010602011771号