2

I am facing a problem in lazy propagation of segment tree. I have an array A, of length N ,of smaller arrays (of max length 20). I also have an array of indices B, referring to the index i am currently pointing to in the array Ai.

There are 2 operations,: a) update the pointers of B for a given range to point to the next element. b) print the max of the values the pointers are currently pointing to in the given range.

for example:-

 int[][] array=
{
    {1,2,3,4},
    {8,4,0,0},
    {3,4,2,5}
};
int[] B={1,1,1};

On making a query for range 1,2 max is 8. This is because the pointers of array B are pointing to the first elements of the array.So we are working with 1,8.

On making a query of 2,3 max =8; this is because we are working with the values 8,3. In general,

int max(int[][] arr,int[] b,int l,int r){ 
    int max=0;
    for(int i=l;i<=r;i++){
        max=Math.max(max,arr[i][b[i]]);//using java Math class here
    }
    return max;
}
void update(int[] b,int l,int r){
    for(int i=l;i<=r;i++){
       b[i]++; 
    }
}

These are the two methods in a very simple form. However ,due to large input constraints, i need a O(logn) query and update time.That is why i thought of using segment trees(currently it's complexity is O(n^2).However I cannot seem to figure out how to update the intermediate nodes in lazy propagation.

Any insight will be helpful. Also, if you could link any similar problem online, it would be really helpful as I could not(I do not know of any such as this is not from any website). Thank you for any help.

NOTE : If b[i]>a[i].length then replace a[i][b[i]] with 1.

Rajarshi basu
  • 330
  • 1
  • 10
  • I believe this is problem DIVMAC. Please try to solve it yourself! – xrisk Sep 10 '16 at 11:53
  • What is DIVMAC?Is it a standard algorithm or something related to segment trees?OK, that is a contest problem.But is the problem not on division repeatedly?But if I think this answer could lead to a solution for that problem,then it is okay,i will wait until that contest gets over – Rajarshi basu Sep 10 '16 at 16:54
  • :) I actually don't know whether this algorithm can solve that problem :P – xrisk Sep 10 '16 at 17:01
  • Anyway, I did not know of that problem at the time of asking the question.Please try to solve this problem.That DIVMAC problem does not seem to be that difficult,though. – Rajarshi basu Sep 11 '16 at 03:45

0 Answers0