Find number of items with weight k in a range (with updates and queries)
<p>I am trying to solve the following problem:</p>

<blockquote>
  <p>Given an array of items with integer weights (arbitrary order), we can have 2 possible operations:</p>
  
  <p>Query: Output the number of items that are of weight k, in the
  range x to y. <br/>
  Update: Change the weight of an item at a certain
  index to v.</p>
</blockquote>

<p>Example:</p>

<p>Given the array: [1,2,3,2,5,6,7,3]</p>

<p>If we query for the number of items with weight 2 from index 1 to 3, then the answer would be 2.</p>

<p>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.</p>

<p>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.</p>

<p>Is anyone able to advise me of a better solution?</p>