You have done a ~~very silly ~~mistake in your code ,<br>
in line no. 55 , <br>in Data query(int l, int r, int s, int e, int node) function.<br>
here it is,<br>
make the above function as follows:<br>
Data query(int l, int r, int s, int e, int node)
{
Data d;
if(s>r || e<l)
return d;
else if(s>=l && e<=r) //use this instead of '(s>=e && e<=r)'
return tree[node];
int m = s+(e-s)/2;
if(l>m)
return query(l,r,m+1,e,2*node+1);
else if(r<=m)
return query(l,r,s,m,2*node);
else
{
Data lQuery = query(l,r,s,m,2*node);
Data rQuery = query(l,r,m+1,e,2*node+1);
calc(node,d,lQuery,rQuery);
return d;
}
}
The AC solution of your code is [here.][1]
Here you have to check whether the current node is completely inside the range or not.<br>
If it is completely inside the range, then return the node.
I have solved the same problem, you can see my solution on [github.][2]
<br>
Hope this is helpful. If you still don't get anything ,feel free to ask.
[1]: http://ideone.com/AVZs4f
[2]: https://github.com/av-anoop/Competitive-programming/blob/master/spoj_GSS1.cpp