https://www.codechef.com/viewsolution/20671922
why was this solution showing a sigsegv error when I used a prefix sum array to solve the problem?
Any help would be appreciated. Thanks in advance.
https://www.codechef.com/viewsolution/20671922
why was this solution showing a sigsegv error when I used a prefix sum array to solve the problem?
Any help would be appreciated. Thanks in advance.
The only reason i can see is int overflow just make array presum i.e. a and variable i long long. The overflow is causing your variable i to go less than 0 which will make -ve array indexing and hence RE.I guess you will get the idea
Yes, the problem occurs at line 21 in your code. If the input is large and value of ‘i’ gets above INT_MAX, ‘i’ overflows for next iteration and the indexing gets disturbed ! Hence SIGSEGV.