File size: 796 Bytes
7a8878c
1
You have an array a of n elements. There are also q modifications of the array. Before the first modification and after each modification, you would like to know the following:What is the minimum length subarray that needs to be sorted in non-decreasing order in order for the array a to be completely sorted in non-decreasing order?More formally, you want to select a subarray of the array (l,r) with the minimum value of r−l+1. After that, you will sort the elements al,al+1,…,ar and want the condition ai≤ai+1 to hold for all 1≤i<n. If the array is already sorted in non-decreasing order, then l and r should be considered as equal to −1.Note that finding such (l,r) does not change the array in any way. The modifications themselves take the form: assign apos=x for given pos and x.