gtheoden42's blog

By gtheoden42, history, 8 months ago, In English

Recently I was solving 1677B - Tokitsukaze and Meeting task and came up with a solution involving range sum update and point query. I implemented this simply using a Lazy Segment Tree for which I used this template from sharmaharisam.

However, my code gave a runtime error on test case 3 with GNU G++17 7.3.0 set as compiler but got AC with GNU G++20 11.2.0 set as compiler. I have no idea why this is happening but need help so that I can answer what is that which is not supported with the GNU G++17 that leads to the runtime error.

Here is the G++17 submission: 223460126 Here is the G++20 submission: 223458461

The two codes are exactly the same.

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

»
8 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

The same happened with this submission: 223460828. I am now extremely curious about what in this template is causing this because all I can see is some standard non fancy C++ functions :)

»
8 months ago, # |
  Vote: I like it +1 Vote: I do not like it

in push_down function

if(2*v + 1 <= 4*n) {
    //...
    lazy[2*v + 2] = combineUpdate(lazy[2*v+2], lazy[v], tm+1,tr); 
}

Definitely incorrect expression in if. I'd say it must be 2*v + 2 < 4*n. But it's up to you to check.

Counter test (got with random generation):

1
7 6
110000111000010000000011011101011000100100
  • »
    »
    8 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    This seems to fix it, Thanks. Any idea why it passes with G++20 though?

    • »
      »
      »
      8 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      It's not about standard, it's about compiler version. I can assume different memory layout, nothing else can cross my mind.