Codeforces и Polygon могут быть недоступны в период с 23 мая, 7:00 (МСК) по 23 мая, 11:00 (МСК) в связи с проведением технических работ. ×

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

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

Hey!

I was solving a problem on RMQ with the help of segment tree, but was consistently getting a SIGSEV error on submission. This was solved(gotAC) by making the size allocated for the segment tree to 6*n instead of 4*n. The segment tree implementation was a recursive one. Why did it need 6*n elements allocated since 4*n should be able to handle the worst case size.

Implementation: https://pastebin.com/usxY7ZgA Problem: https://www.spoj.com/problems/AKVQLD03/

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

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

In your build function, even when you've assigned some value to leaf node, you're still taking the sum of 2*node and 2*node+1. That will overflow from regular 4*n, causing SIGSEV.