In the solution there are the following lines:
if(r>=n)
{
update(0,0,n-1,l,n-1,a[i]);
update(0,0,n-1,0,r-n,a[i]);
}
else
{
update(0,0,n-1,l,r,a[i]);
}
And then in the queries loop again there is something similar:
if(r>=n) // cyclic update on ranges [l,n-1] and [0,r-n].
{
update(0,0,n-1,l,n-1,y-a[l]);
update(0,0,n-1,0,r-n,y-a[l]);
}
else //simple update on range [l,r]
{
update(0,0,n-1,l,r,y-a[l]);
}
Could you please be more detailed about the following points:
- Why there are two calls of update(…)
- Why in the first call the [l, r] is [l, n-1] and in the second call [l, r] = [0, r - n]
- Why in the query section the update was called with y - a[l] as a val ?