Hello all, I am solving Problem and it is running fine in my computer. I also checked on ideone.com and there also it is giving expected output but it is giving runtime error on codeforces(Exit code is -1073741819) Submission. Can anyone help me and tell reason for this weird behavior? Thanks in advance.
In line 52, the statement
a[i].erase(it);
erases from the dynamic memory the item ina[i]
whose address is stored in the iteratorit
. In line 45, the post statement of the for loop included in the macrotr(a[i],it)
attempts to executeit++
after erasing the item. This generates a segmentation fault.You should not increment
it
after erasing the item. Instead, storeit
in another iterator variableiv
, incrementiv
, erase the item whose address is stored init
, and then store the address iniv
back toit
. Replace lines 45-54 with the following lines:This should fix the problem.