WHAT TO LOOK FOR IN A PROGRAM IN ORDER TO FIX THE SIGSEV ERROR ?
Its basically the error which is caused by an invalid memory reference or the segmentation fault. A segmentation fault occurs when we are trying to access a memory location we are not allowed to or access it in a way which is not allowed. On X86 system, we have a data segment and stack segment. These two parts of the programās address space are writable while others are readable(Code segment). Thus attempting to read outside of the programās address space, or writing to a read-only segment of the address space, results in a segmentation fault, hence the name. Refer this answer by admin to look in for the common issues which raise this fault.
After few tests i found that my program is actually getting
terminate called after throwing an instance of āstd::bad_allocā
what(): std::bad_alloc
Can you help me with this please
The exception is usually thrown when the dynamic memory you are trying to allocate is of a large size and OS is unable to allocate it. So, try changing your codeās logic and optimize the space. Or you may like sharing your code, weāll try helping here
Ya ofcourse
This RTE is because of the fact that the new operator you are using to allocate memory is allocating an array of size n. At the run time you havenāt provided that value of n and thus it is allocating memory of some unspecified size(garbage value of n it is picking). Thus, if youāll give some input and then check itāll work fine. Also, you used a macro for MAX and used max as a variable. This causes ambiguity. Also, āmaxā is a keyword in C++. In some version itās not allowed to use it. Like in yours, it showed the error that reference to max is ambiguous.
See here, http://ideone.com/AmeWXz I displayed the values of your segment tree and it works absolutely fine.
Link is not opening
itās ok now
i copied your code and executed it
and it is also giving the same runtime error
@ravidelcj Did you give any input? I canāt see the custom input, Did you read above? I 'll repeat again: You are not given any input and your variables are assigned some random garbage value. Lets say na has -4357 or anything. When your code runs, the tree construction function is called and it starts allocating memory (lines 28-30) which the OS is unable to do. Thatās why it is throwing exception. Give input and itāll work fine!! Read above answer and comments carefully please.
i am really sorry
i forgot to give the inputs
btw thanks
you once again helped me
this is a question from spoj GSS1
and its giving SIGSEGV
please help
SIGSEGV means, you are allocating such large memory which is not allowed. And GSS1, this question is not asking what you are doing, its asking which range among the given (i,j) has got the maximum sum. Refer http://e-maxx.ru/algo/segment_tree for that. It has a good explanation of that question. Since, it seems you are just beginning with Segment tree, try solving other basic questions like MTSICK, MARBLEGF etc on codechef to get better understanding of the concept. Thatāll really help. Even I started with that GSS1 question months back but then shifted.
so how are we supposed to handle large inputs in this case
and what do you mean by range among given i j with max sum ?
You are not supposed to handle large inputs, you are supposed to handle the space you are allocating which is large due to large input size. Secondly, the question says which range among the given (i,j) has got the maximum sum. Ex: in range [1,3], the possible ranges are [1,1],[2,2],[3,3], [1,2], [2,3], [1,2,3] question asks which range among all these has maximum sum. SOlution is explained on that russian site i mentioned in the above post.
For further assistance, I think itās better to have a new thread/forum for that question specifically and closing this after marking the answer accepted. Youāll get more and better answers on that separate thread titled for that question. Happy to helpā¦