Sherlock and Queries

  • + 2 comments

    I wrote a code whose complexity is approximately O(M*log(N)) in avarage case.(in best case O(M)). When integers of B arrays become small number such as 15-20, complexity approach O(N*M) which is worst case. What is the trick of this question? Make worst case and avarage case complexity linearithmic time or better?