This morning, I spent nearly four hours to solve 455D - Serega and Fun, but I got "Runtime Error on test 9" again and again. This is one of my submissions: 132502463.
By constantly checking where the RE occurred, I located the wrong code to this line:
dq[bl[r]].erase(dq[bl[r]].begin() + r - lbl[r]);
My interpretation of it is: Delete the $$$(r-lbl_r)$$$-th element of deque dq[bl[r]]
. I guess it may be because r-lbl[r]
is out of bounds ($$$\notin [0,\text{size of deque})$$$) and a non-existent element is deleted, which leads to RE. But after I added two lines of assert()
, I found that this is not the case.
In one attempt, I added a pair of parentheses:
dq[bl[r]].erase(dq[bl[r]].begin() + (r - lbl[r]));
But surprisingly, I got "Accepted". That's very strange. I think there is no difference between "an iterator that moves $$$x$$$ forwards and then $$$y$$$ backwards" and "moves $$$(x-y)$$$ forwards".
I want to know the difference between these two pieces of code, could someone tell me?