0

Given an array with n integers. The following q queries of 2 types have to be handled :

1) Given k and c, add c to all indices which are factors of k

2) Output value at a given index

Whats an approach to handle each query with O(logn)/O(1) complexity ?

My attempt : Calculate all factors of k and update indices. But complexity of this approach is O(q*sqrt(n)). I thought of creating some tree type data structure to store values in but couldnt proceed ahead.Any solution/hint on how to proceed ?

Rohit
  • 1

0 Answers0