Insert number into the array so that a[i] <= i
assume k's number has been inserted before index j,
1) a[j] <= k + j no need to add more numbers bofore a[j]
=> k = k (when a[j] - j <= k)
2) a[j] > k + j, at least (a[j] - j - k) more numbers are needed.
=> k = k + a[j] - j - k = a[j] - j (when a[j] - j > k)
Therefore k = max(k, a[j] - j)
Complexity: O(n)
each single element is also a subarrray of a and its longest increasing subsequence is 1.
XOR (even number of 1) = 0
Therefore:
1) If the length of the original array is even, split the array into subarrays with length of 1. Even number of 1 satisfies the requirement natually.
2.1) If the length of the original array is odd, however, exits a pair that a[i] >= a[i+1], split these two elements into one subarray. Others remind the same as the 1). Still even number of 1.
2.2) Length(n) is odd, no pair a[i] >= a[i+1] => the array is strictly increasing.
If (h[1] + h[2] + ... + h[k] = n) and (h[1] XOR h[2] XOR ... XOR h[k] = 0) exists, since each segment s[i] is strictly increasing => h[i] = b[i] (length of s[i]).
Then (b[1] + b[2] + ... + b[k] = n) and (b[1] XOR b[2] XOR ... XOR b[k] = 0) => the last bits of all b must contain even number of 1. Yet n is an odd number. Contradiction!
Only 1) and 2.1) are possible here.
Complexity: O(n)
Link to C: Di-visible Confusion
A element - a[i] can be removed only when there exist a number x in [2, i+1], so that the element is NOT divisable by x.
Improvement:
if a[i] can be divided by any number between [2, i+1]
==> a[i] >= LCM(2, 3, ..., i+1) [Notice: LCM(2,3,4,..,23) > 1E9 ]
Therefore, if i >= 22, a[i] must be divisable by a number between [2, i+1].
Conclusion:
1) i >= 22, a[i] can always be removed
2) 1 <= i < 22, using bruteforce to check every number in [2, i+1];
Complextiy: O(n + 21^2)