Please help me with this Segment Tree problem

segment_tree

#1

hey any ideas for this…i have an array,i build a segment tree of that array now i have given a range of indexes and for that i have to return the value of index at which there is a max_element,suppose my array is [1,7,3,9,5] and range of index is [1,3] so my output should be 2(as on index 2 there is max element in the range (1,3)…example 2: if my array is [1,1,7,3,5] and index ranges is (1,3)(indexing 1 based) then my output can be either 2 or 3 both is fine… any help would be apprectiated.


#2

yeah this can be done by using segment trees.Instead of storing the maximum value,store the indexes of maximum elements in each node of the tree.


#3

This can be easily done with Segment Trees.

You have to keep only 2 things in mind :-

  1. What to store in the nodes: Store the index with the maximum element in it.
  2. How to merge 2 nodes: Store the data of that node which has the bigger element in it.

You can refer to my code in the following link if you get stuck.

https://pastebin.com/UTXH8QF5


#4

I have edited your post to become a separate Q. Please add more details here :slight_smile: