I_Hate_Swaps's blog

By I_Hate_Swaps, 3 years ago, In English

Given two arrays a[n] , b[m] and q queries : In each query we have to update b[a[i]] to x for i = {l......r}

If not segment trees ,is there any efficient method to process such queries ?

  • Vote: I like it
  • +8
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
Rev. 2   Vote: I like it +8 Vote: I do not like it

Yes. Maintain an array $$$c$$$ where $$$c[i]$$$ stores the value of $$$b[a[i]]$$$. Carry out all the updates on this array first, then map the indices back to the original indices and do whatever you want to do with the array. This assumes $$$a$$$ is fixed throughout.

Edit: This works only if $$$a$$$ doesn't have duplicates.