Using python develop code for the following porblems:Problem: Let's call arrays of the form x x+1 ... x+k proper. In other words, proper arrays are arrays that form increasing arithmetic progression with the difference of one.You are given an array of N integers. Let's denote it's numbers by a1, a2, ..., aN. You are also given M change queries. Every change query is a query of the form "X Y" with the meaning that the X-th number in it becomes equal to Y. We perform these queries one after another, strictly in this order. Please, calculate the length of the longest proper subarray of this array, i.e. the length of the longest segment [L; R] that (aL, aL+1, ... aR) is a proper array before all the queries and after every query. The first line of input consists of two integers N and M, separated by a single space - the length of the array and the number of queries.The second line of input consists of N integers, the i-th equals to ai - namely the i-th number in the array.The following M lines contains the queries in the form "X Y", where X and Y are natural numbers with the meaning that the X-th number becomes equal to Y.Output the length of the longest proper subarray of the initial array at the first line of output. Then, output M integers at separate lines. The i-th such line should contain the length of the longest proper subarray after the i-th changing query.Anytime ai <= 2 * N holds.
Using python develop code for the following porblems:Problem: Let's call arrays of the form x x+1 ... x+k proper. In other words, proper arrays are arrays that form increasing arithmetic progression with the difference of one.You are given an array of N integers. Let's denote it's numbers by a1, a2, ..., aN. You are also given M change queries. Every change query is a query of the form "X Y" with the meaning that the X-th number in it becomes equal to Y. We perform these queries one after another, strictly in this order. Please, calculate the length of the longest proper subarray of this array, i.e. the length of the longest segment [L; R] that (aL, aL+1, ... aR) is a proper array before all the queries and after every query. The first line of input consists of two integers N and M, separated by a single space - the length of the array and the number of queries.The second line of input consists of N integers, the i-th equals to
Input
5 1
1 4 3 5 2
2 3
Output
1
1
Step by step
Solved in 5 steps with 3 images