UVA 1608 not boring sequences (with summary of common algorithm design and optimization strategies)
The purple book has such a problem:
It is not boring to call this sequence if there is at least one element in any successive subsequence of a sequence that appears only once. Enter a sequence of n elements to determine whether it is a boring sequence. n<=200000.
First, find the element AI that appears only once in the entire sequence. If you can't find it, it's boring. Otherwise, you can exit the current loop, recursively judging [1, i-1] and [I+1, N] is not a boring sequence. However, how to find AI is very important. If you start looking from one end, then the worst-case time complexity is O (n^2). And if you start looking at both ends, then the worst case becomes AI in the middle, the time complexity is O (NLOGN)! This is because in the middle of the search is slow, split up fast, and at both ends of the find up fast, divided up slowly. Sometimes it's important to use a good halfway meeting!
Here are the common algorithm design strategies and optimization strategies that are used in purple books (note that this is a design strategy, not an algorithm):
Construction method (tectonic solution),
Halfway through the method (usually better than many encounters),
Problem decomposition (two unrelated issues are split up and solved separately),
Equivalent conversion (simplification),
Assumptions (using symmetry to avoid discussion),
Using the data structure (accelerating the algorithm without changing the main algorithm),
A combination of several shapes (usually associated with a sliding window),
Two-point answer (the optimal value will be determined to determine the optimal value, also in the strategy),
Scanning method (with sequential enumeration method, which usually maintains some important quantities),
Enumeration Datum (looking for the optimal value based on the current datum, then the maximum value of all the benchmarks),
Sliding windows (Maintenance monotonicity, efficient removal of redundant state) and so on.
UVA 1608 not boring sequences (with summary of common algorithm design and optimization strategies)