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

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

Update: The problem was in my 'decompose' function. Its return type was 'int' though I didn't return anything, so I changed it into 'void' and I got AC. Weird but worked.

I tried to solve this problem using HLD and Segment Tree. I didn't find LCA explicitly rather used HLD.

Code: https://pastebin.ubuntu.com/p/BfxMZH9hz3/

This solution gives runtime error. I can't find any reason for this kind of verdict.

I have already read this blog but couldn't understand why my code isn't working.

Can anyone help me?

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

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

You are asking what's wrong with your code? You should be asking what's wrong with yourself first. Fancy posting a wall of unreadable code without any explanation at all. I don't think anyone's gonna help you to debug.

  • »
    »
    5 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    nik7 I thought someone from their previous experience may give any hint/testcase that will help me to understand RTE. I never asked anyone to read my code, though I should have explained/comment it (Sorry for that). But even if I did, you with your big ego won't be able to understand it.

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

Your HLD query is wrong, you may have that head[b] is a parent of lca(a, b) node. it would be better if you could find lca correctly.