dltwecntn's blog

By dltwecntn, history, 2 years ago, In English

Link to the submission: Here. I don't know why it got runtime error when using reference for variable $$$i$$$ (index of the current note in the segment tree in build function).

  • Vote: I like it
  • +1
  • Vote: I do not like it

| Write comment?
»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Unlucky :(

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it
if (i == 0) {
    i = sz(tr);
    tr.pb(Note(0, 0, 0, 0));
}
...
build(tr[i].left, l, mid);
build(tr[i].right, mid + 1, mid + (1 << len));
build(tr[i].extra, mid + (1 << len) + 1, r);

You do some strange thing, I cannot tell why it should work in first place.

»
2 years ago, # |
  Vote: I like it 0 Vote: I do not like it

ok

»
2 years ago, # |
  Vote: I like it +4 Vote: I do not like it

Can someone help me please ;-;.

  • »
    »
    2 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
    if (i == 0) {
        i = sz(tr);
        tr.pb(Note(0, 0, 0, 0));
    }
    ...
    build(tr[i].left, l, mid); // because i is passed as reference it may change value of i and than 
    
    build(tr[i].right, mid + 1, mid + (1 << len)); // when you call this function i can be different than previous
    
»
2 years ago, # |
  Vote: I like it +1 Vote: I do not like it

Really interesting, I think the problem is that i sometimes gets trash value after build(tr[i].extra, mid + (1 << len) + 1, r). I don't know why, though. The code looks fine to me actually.