Subject to the effect:
Given a sequence of length n, a, m queries, each query for a given interval [l, r], to obtain the minimum interval of all sub-sequences and.
Topic solution:
- Off-line algorithm (Mo Team)
Obviously, this does not modify the query we can consider Mo team. The difficulty is how transferred from [l, r] to [l, r + 1] (the same way several other metastasis). We find the answer to such a transfer to bring the contribution that is the left point [l, r + 1] for all the right point range minimum and r + 1. If we can value O (1) complexity is calculated so there is no problem. So consider pretreatment. fr [l] [r] indicates the left end point [l, r] r right end points of all sections and the minimum value.
We expect static algorithm to find a minimum common st. After pretreatment O (n log n), for each interval, we can O (1) obtain the minimum value within the interval. Minimum set [l, r] p in this position, then obviously, when the minimum value are left at the time point [l, p] a [p]. We just need to calculate fr [p + 1] [r] to. We note fr obviously not the array is two-dimensional, then we have to compress it. We removed the first dimension to give fr '[r] indicates the left end point [1, r], r minimum and right points of all sections. We note that if fr '[r] by subtracting the minimum interval of all points in the left [l, p] r and the right point to give fr [p + 1] [r]. We further note that because p is the position of the minimum interval, thus [p + 1, r] be not less than the number of A [p] that is the left end of the all minimum interval [L, p] r of the right end point and equivalent to the left end of the [L, p] and the right end of all minimum interval, i.e., fr 'in the p [p].
Thus, as long as we fr '[r] out of the array pretreatment, O (1) updates each modification can be achieved. A reintroduction array LST [i] denotes the i is smaller than a number (can be obtained with a stack, or the like 'bit), then the fr' [r] = fr '[lst [r]] + a [r] * ( r-lst [r]).
Symmetrically, we also need a left end recording fl array fixed point, for transferring process changes l.
the complexity
- Online Algorithms
Or start from the minimum range position st algorithm obtained. For an interval [l, r], if the minimum position p, then all the left end points [l, p] at the right end of the minimum value of the interval [p, R & lt] should have a [p]. The only remaining point range all located on one side of p.
Discussed left and right symmetry.
The answer to the left of that is , to deal with what prefix and O (1) is calculated.
Complexity of O (n log n)