Sunday, 25 December 2016

Interesting Segment Tree Problem

Link To Problem


Node Properties {

     no. of 4 in range (n_4)
     no. of 7 in range  (n_7)
     longest increasing subsequence length (n_i)
     longest decreasing subsequence length (n_d)

}


Node Updates {

   swap(n_4,n_7)
   swap(n_i,n_d)  
   // Due to the reason that i.e 44747  LIS = 4   LDS=2
       After Swap Operation      77474  LDS=2    LDS=4
}

Merge Node Updates{

     n4[parent]=n4[left]+n4[right]
     n7[parent]=n7[left]+n7[right]
     n_i=max(n_i+n7,n4+n_i,n_4+n_7)

}

Query{
   return n_i
}
    

No comments:

Post a Comment