Help required in a Segment Tree problem

Hello coders,
How to find the leftmost and the rightmost occurence of an element x in an array, using segment tree. At present , I only know how to build a seg tree, update and query it.
Thanks in advance!

Well, it definitely doesn’t need a segment tree. Use an array / map (depending on the range of values) of sets for each value, such that each such set stores the indices the value appears at. Gives you logarithmic time lookup and updates.