Unexpected behaviour of memory allocation in C

I am trying to solve MSTICK problem from May Challenge 2013

I tried normal segment trees (without lazy propagation) but kept getting SIGSEGV.

While debugging, I tried to vary memory allocations. These are the two codes I wrote

(Differences are mentioned in comments in the codes)

These are completely identical to each other except for memory allocation techniques used. And still, they are giving different answer to the same input.

Could anyone explain why is it so?

Bdw, I figured out why I’m getting SIGSEGV. Its because the segment tree size needs to be 2 times the size of original array.
I am still interested to know the explanation of the above mentioned behaviour