Hi everyone, I was solving the problem from the recently ended contest May Circuits! https://www.hackerearth.com/may-circuits/algorithm/make-n00b_land-great-again-circuits/
But I faced a really strange problem! Here my AC submission: https://ideone.com/QxhGT6
// -----
int hey = update2(l, r, x, (v == -1 ? -1 : t2[v].l), tl, tm);
t2[now].l = hey;
hey = update2(l, r, x, (v == -1 ? -1 : t2[v].r), tm + 1, tr);
t2[now].r = hey;
// -----
/* t2[now].l = update2(l, r, x, (v == -1 ? -1 : t2[v].l), tl, tm);
t2[now].r = update2(l, r, x, (v == -1 ? -1 : t2[v].r), tm + 1, tr);*/
But if replace the first part with the second, even sample isn't working! I really need your help.
My guess is that in this line:
the order of evaluation is the following:
Because
update2
function adds elements to the vectort2
, reallocation happens andtmp
no longer points to a valid location.Thank you! I think I understood my problem! :) I really appreciate it!