My submission for the MARBLESGF prob(Dec13 Long) was based on the idea that I store the initial sum a[o] to a[i] in s[i], and then keep a track of all the changes made, so that whenever sum is asked for I need to just add these changes to it.
The foll sol( http://ideone.com/aum9W7 ) got accepted in which I keep track of the changes in an array, which takes O(Q) time in worst case to compute the sum and hence O(Q^2) for the whole prog.
While in the sol( http://ideone.com/nQpx7n ) where I got TLE, I kept track of the changes using a Red-Black tree so that in worst case to compute the the sum it would be of O(R+log Q), where R would be the no of elem that have been changed, within the range of elem whose sum is to be calculated.
Any reasons for this?