SPOJ GSS1 Segment tree

I am getting a SIGSEGV for Spoj GSS1

my solution --> http://ideone.com/HPev59

Please help !!