# How to use lazy propagation on segment tree in case of node's value is updating via XOR?

The problem is to update the elements of the range [L, R] via XOR- ing each of them with the given X.
In the case of just a normal segment tree, we can use lazy propagation to calculate the parent node sum value just in this way:

`(end - start + 1) * val`

And the whole code for an update, in this case, could be like as shown below:

``````void updateRange(int node, int start, int end, int l, int r, int val)
{
if(lazy[node] != 0)
{
tree[node] += (end - start + 1) * lazy[node];
if(start != end)
{
lazy[node*2] += lazy[node];
lazy[node*2+1] += lazy[node];
}
lazy[node] = 0;
}
if(start > end or start > r or end < l)
return;
if(start >= l and end <= r)
{
tree[node] += (end - start + 1) * val;
if(start != end)
{
lazy[node*2] += val;
lazy[node*2+1] += val;
}
return;
}
int mid = (start + end) / 2;
updateRange(node*2, start, mid, l, r, val);
updateRange(node*2 + 1, mid + 1, end, l, r, val);
tree[node] = tree[node*2] + tree[node*2+1];
}
``````

But the problem in the case of XOR is that we canâ€™t write something like (end - start + 1) * val for the parent node?
So which techniques could be applied in such a case?

Usually, also the children need to be updated like the parent in the lazy update, somethings like that, but you need to define what is the operation that are trying to make. Maybe `end - start + 1` it is wrong in the children

``````   if(lazy[node] != 0)
{
tree[node] += (end - start + 1) * lazy[node];
if(start != end)
{
lazy[node*2] += (end - start + 1) * lazy[node];
lazy[node*2+1] += (end - start + 1) * lazy[node];
}
lazy[node] = 0;
}
``````

My work on Segment tree can be found here