You are given an array \(a_1,\ a_2,\ \dots ,\ a_N\) consisting of \(N\) elements. You are given \(Q\) queries. Each query is of the following types:
- The format of the first type of query is \(1\ L\ R\ x\). You must increase the values of all elements in range \(L\) to \(R\) (both inclusive) by integer \(x\).
- The format of the second type of query is \(2\ L\ R\ y\). You must multiply the values of all elements in range \(L\) to \(R\) (both inclusive) by the integer \(y\).
- The format of the third type of query is \(3\ z\). You are required to find the maximum distance between elements that are equal to \(z\) in the array. If the element is not present in the array, print -1.
Input format
- The first line contains an integer \(N\).
- The next line contains \(N\) integers \(a_1,\ a_2,\ \dots ,\ a_N\) denoting the elements of the array.
- The next line contains \(Q\) denoting the number of queries.
- The next Q lines contain one of the 3 queries mentioned above.
Output format
For every query of Type 3, print an integer denoting the maximum distance \(j-i+1\) where \(1 ≤ i,\ j ≤ n\).
Note: The query of type 3 is present at least once in the problem.
Constraints
Note: No \(a_i\) exceeds \(10^{18}\) after updates.
after 1st query, the array becomes:
2 3 3 4 5
after 2nd query, the array becomes:
6 9 9 12 5
3rd query: the distance is 2 (a2 = 9 & a3 = 9)
after 4th query, the array becomes:
6 9 9 12 6
5th query: the distance is 5 (a1 = 6 & a5 = 6)
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor