Given an array A with N numbers(all positive and contain less than or equal to 4 digits), 2 types of queries are to be supported. There are total M queries.
- Update a range given by indices L,R(both inclusive) by K.
- Return the maximum element in a range given by L,R(both inclusive).
Updating a number K times implies rotating the number K times.
For e.g. 1234 rotates into 2341
905 rotates into 059 and 059 rotates into 590.
Note : 059 and 59 are different numbers. 59 rotates into 95.
Given array elements don't have leading zeroes.
Constraints:
0 <= Ai < 10000
1 <= N <= 800000
1 <= M <= 200000
0 <= K <= 60
I thought of a segment tree in which the tree nodes store the number of rotations of the range they contain. I implemented this with lazy propogation but with the lazy propogation too my query implementation takes O(N) time in the worst case, which is leading to TIME LIMIT EXCEEDED.
Can anyone propose a faster approach?
Am I missing some property of the array or structure?