I am trying to solve the following problem:
Given an array of items with integer weights (arbitrary order), we can have 2 possible operations:
Query: Output the number of items that are of weight k, in the range x to y.
Update: Change the weight of an item at a certain index to v.
Example:
Given the array: [1,2,3,2,5,6,7,3]
If we query for the number of items with weight 2 from index 1 to 3, then the answer would be 2.
If we modify the element at index 2 to have a weight of 2, then we make the same query again, the answer would be 3.
This is certainly a segment tree problem (using point updates). However, I am facing a problem here - each segment will only hold the answer for 1 index. Hence, it seems that I must use vectors in my segment tree. But this would overcomplicate things. Furthermore, I am not sure how to do that either.
Is anyone able to advise me of a better solution?