G - Celester 2 Editorial
by
psgqwq
editorial
Finding the answer for a fixed \(k\) can be solved using minimum-cost maximum-flow, which demonstrates that the minimum number of operations is convex with respect to the answer. Let \(f(l,r,0/1,0/1,i)\) denote the minimum number of operations for the interval \([l,r]\) such that after the operations, the value at \(l\) is \(0/1\), the value at \(r\) is \(0/1\), and there are \(\ge i\) occurrences of \(01\). Then \(f(l,r,0/1,0/1)\) is a convex function. The divide-and-conquer merger can be optimized using the Minkowski sum, yielding a time complexity of \(T(n) = 2T(n/2) + O(n) \implies T(n) = O(n \log n)\).
posted:
last update:
