#P11901. Dynamic Array Segmentation with Forced Cuts
Dynamic Array Segmentation with Forced Cuts
Dynamic Array Segmentation with Forced Cuts
Given m arrays s₁, s₂, …, sₘ and an array t of length n, we define a function f(l, r) as the minimum number of segments required to partition the subarray tₗ, …, tᵣ into contiguous segments (or pieces) such that each segment appears as a contiguous subarray in at least one of the given s arrays.
In addition, there are forced segmentation constraints: at some positions between adjacent elements of t you may be forced to make a cut. Specifically, if a forced segmentation is active between tₚ and tₚ₊₁, then any valid partition of t must have a segment boundary at that position.
You are given the arrays and then required to process q operations. There are three types of operations:
- Toggle Forced Segmentation: For a given position p (1 ≤ p < n), toggle the forced segmentation between tₚ and tₚ₊₁ (i.e. if it is already set then cancel it, otherwise add it).
- Update Operation: Replace the subarray tₗ, …, tᵣ with a given array a of length r - l + 1.
- Query Operation: For given indices l and r, compute f(l, r) with the condition that any forced segmentation in the interval must be obeyed. It is guaranteed that a valid segmentation exists for every query.
Your task is to process these operations and output the answer for every query operation.
Note: If there are forced segmentation cuts within the queried interval, then you must partition the interval accordingly and compute f(l, r) as the sum of the minimum segmentation counts over each continuous block between forced cuts.
inputFormat
The input begins with three integers m, n, and q.
Then, for each i from 1 to m, a description of the array sᵢ is given in one line starting with an integer k (its length) followed by k integers.
The next line contains n integers representing the array t.
Each of the next q lines describes an operation in one of the following formats:
1 p
– Toggle the forced segmentation at position p (1 ≤ p < n).2 l r a₁ a₂ ... a₍r-l+1₎
– Update the subarray t[l...r] by replacing it with the given array a (of length r - l + 1).3 l r
– Query to compute f(l, r).
outputFormat
For each query operation (operation type 3), output a single integer on a separate line – the minimum number of segments needed to partition t[l...r] in accordance with the forced segmentation constraints.
sample
2 5 5
3 1 2 3
3 2 3 4
1 2 3 4 3
3 1 5
1 3
3 1 5
2 2 4 2 2 3
3 1 5
3
3
4
</p>