Segment tree problem range minimum query

Link to solution :

I am solving range minimum query for segment tree but update operation is giving wrong output.

Testcase :

6 5

1 5 2 4 3 0

q 1 5

u 5 -1

q 1 5

q 1 4

q 1 3

condition on line no 51 is wrong

it should have been

if(idx>=low && idx<=mid)

instead of

if(idx>=low && idx<=high)
1 Like

Use 1 based indexing everywhere. Even i was getting a wrong answer when i first tried the question. But switching from 0 based to 1 based indexing fixed it like magic. If it doesnt, get back to us ^^

what @shreeshaprabhu said is correct.

There are much much easier ways to implement segment trees as well. look my code for this same problem : http://ideone.com/5jPjvT

Read this for explanation : http://codeforces.com/blog/entry/18051

NO the problem was in line no 51 only!!