Hey guys, i need some help/clarification on sets.
(I searched for this but couldnt find anything relevant. Hence i would be grateful if you guys could help )
Its with reference to problem XORSUB 's solution here which used the method of Gaussian Elimination .
With reference to that solution, there is a comment-
The logic is correct. But there is small flaw in implementation. The above code will give wrong output for following test case
1
3 1
12 10 8
This is because of how STL set works. For correct result, just swap these two statements
s.erase(t);
s.insert(t^m);
Why is this in this way? What is the effect of swapping the two statements? What error is caused in this method and how does swapping fix this? The usual pages on sets dont mention this anywhere, and I feel such exceptional cases should be known to the coder. I would be grateful if anyone can explain this