I’m afraid you have misinterpreted the problem statement a little. We have to find out the max{a[i]+a[i+1]+a[i+2]+…a[j]} for (x ≤ i ≤ j ≤ y). Put simply, we have to find sum of contiguous subarray in range (x,y) which has the largest sum. On the other hand, your code seems to be returning only the maximum number in that range, not maximum contiguous sum. That is the reason for the WA.
You misunderstand the question it is asking maximum contigous sum and also your segtree size is 50000 which is same as the size of array but is should be 2n-1 where n is the size of array element so if input array element is 50000 then your code will give sigsegv error means you are trying to access invalid memory means declare segtree size 2n-1
generally it is advised to declare 4 times of segtree size as many times of size of array size
sigsegv error because the size of segment tree is too less than the required one i.e.
if input size is power of 2 e.g. 4 then size of segment tree is 4 * 2 - 1=7
if input size is not power of two then take the number which just greater than the number and is the power of two e.g. if n=5 then size of segment tree is 8 * 2 - 1= 15
Also in solution you have used zero based indexing but while calling the query function e.g
y=rangemaxquery(xi,yi,0,i,0); used but you have to decrease xi and yi by 1 in call function
y=rangemaxquery(xi-1,yi-1,0,i,0);
in code we define array and segment tree globally so no need to write it again and again while calling constructtree() and rangemaxaquery() hope u got my point