Блог пользователя Dazzler

Автор Dazzler, история, 9 лет назад, По-английски

Hello friends, i appeared in codeforces round 433DIV2. My solution for problem DIV2C passed the pretests but didn't pass the system test. Because there was a bug in the line 65 & 66 because i had erased the iterator and then tried to use the value stored at it(i just replaced line 65 & 66 with each other, then solution got accepted). So, it shouldn't have passed pretests even. but still it passed . Can someone explain me this abnormal behaviour of iterator.

  • Проголосовать: нравится
  • -2
  • Проголосовать: не нравится

»
9 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

It is happening because when you delete an element, all iterators lose their reference. Hence, operation *it after the erase line, is illegal.

source: http://www.cplusplus.com/reference/set/set/erase/

read topic : Iterator validity