You are not logged in. Please login at to post your questions!


HELP needed with SIGSEGV using dynamic Segment TREE

I tried the problem and could only come up with algorithms for 1st and 2nd subtask. For subtask 2 I planned to use segment trees, so I wrote a segment tree code for my own use. The BUILD function gives a SIGSEGV error. I have tried the same TREE on leetcode and SPOJ and did not receive any segmentation fault. For sub2 I build a segment tree representing 10^7 buckets and each bucket represents 100 colors for a total of 10^9 colors. Please help me with this, to make it easy to help me I have figured out the following things : 1. Even if I use a small n = 100 instead of 10^7, I receive SIGSEGV. 2. Build function definitely leads to SIGSEGV, as I tried the code with only build and no other code. 3. However when I used n = 64,I Did not receive SIGSEGV. thankyou.

asked 19 Dec '18, 03:38

kartik8800's gravatar image

accept rate: 0%

edited 19 Dec '18, 03:51

Are you out-of-bounds on the array ar? ar is an array length 10000000, and then I think you access it up to index 16777216?

One way to catch this sort of thing is to use vector<t> ar(10000000) in place of ar[10000000]. Instead of accessing ar[x], you would use Any attempt to access outside the bounds of the array will crash with helpful message.


answered 19 Dec '18, 05:41

john_smith_3's gravatar image

accept rate: 27%

Thanks for the reply and I'll try using vector and report back, however I don't feel this is the problem. For leaf nodes I have assigned a 0 if node number greater than n. Also I have tried the code without even using the array, had the code which used array commented out and only built the tree still got Same error.Thanks for the help will still try vector.

(19 Dec '18, 11:15) kartik88005★

Yes, you assign 0 if node greater than n. But you have set n to be larger than the size of the ar array.

   SegmentTree<ll> sg(ar,n);
(19 Dec '18, 12:42) john_smith_35★ check this please even n = 1000 gives SIGSEGV with build function.

(19 Dec '18, 12:56) kartik88005★

Thankyou, was able to fix my problem using turns out problem was not with the tree but with my understanding of the question.

(20 Dec '18, 22:05) kartik88005★
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 19 Dec '18, 03:38

question was seen: 211 times

last updated: 20 Dec '18, 22:05