A pair of parentheses make me RE

Revision en1, by yzy1, 2021-10-20 11:14:18

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". I want to know the difference between these two pieces of code, could someone tell me?

Tags runtime error, debugging

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English yzy1 2021-10-20 11:24:51 154 Add "That's ..."
en1 English yzy1 2021-10-20 11:14:18 913 Initial revision (published)