That’s the same thing happened with me, My solution is exactly like yours but it give wrong ans when i submitted , I tested it on more than 100 test cases locally it give right answer but when i submitted it gives wrong.
The mistake that you have commited is nothing but to obtain current element
You are Xoring with every previous element which is occured before
As you are updating x in every case which is false in each case x should be the previous case’s un-updated y .
In short In order to obtain normal array from prefix array you are expected to XOR with previous element only and not the every element occured before which you are doing in second the Accepted solution
Here Your AC solution with first approach
with some modifications as discussed earlier
I went through Your code and And I just found incorrect logic Which I then corrected and submitted which got accepted
I haven’t run updated code and previous code on any special testcase made by me though and just submitted which got accepted .
Also I tried later but I wasn’t able to find the corner case .
I think there might be a strong corner testcase .
bro u interpreted wrong if u see above solution @sunil5798 is not doing any prefix sum … he just take xor of previous and current value…which is correct in both of cases
see in WA solution if u print x and y , u will see the X is previous value not the xor of array till i , and y = current_Y ^ just previous value.
I think the problem setter is fraud vector se karo AC mil rha ha and array se WA.Kuch to galat horha @admin please take action its a 6 star coder who is complaining one of my junior also told about this problem.What others think?
Intriguing - I can’t find a well-formed testcase where this actually breaks. Of course, this is from a third-party contest so there’s always the possibility of broken test input …
One situation where the outputs may differ is if the test input provides less than N entries for the array - maybe someone could submit a quick test for this? Just adding:
assert(cin);
as the last line in main would do the trick.
Edit:
Hmmm … maybe not. I’d expect this solution to be a RE rather than a WA if that were the case …
So how is vector making a difference sir and can u please give some advice on this matter should c++ coders should always stick to vectors, its important because sometimes there is a prize money for such third party contests as well so
I got ur point sir understood why the top rankers used vector for the same but vector has got issues too like with bound i guess it doesn’t provides exceptions as well but anyways thanks for ur reply sir and thanks for this blog too @sunil5798