SIGSEGV in chef and easy Xor

This is the link to my solution:-

plz help also if their is any logical mistake in the solution in plz point it out i am following rachit jain video for this question

link to question:-

Valgrind is complaining about use of uninitialized memory in lines 42, 44, 56 and 63. I’d guess your ‘i’ and ‘j/sz’ variables get bigger than 100 and you access the co and dp arrays out of bounds.

1 Like

is the problem still there or you figured it out? I found that runtime error starts at N=1000 part, but could debug no further.

1 Like

@vijju123 i think it is still there is their any other logical mistake in my code you’r reply is very helpful thank’s for you’r reply you how did you debug can you explain

thank for the reply but according to constraints it should not get bigger than that i will have a look in my code thanks again

check line 50. You probably meant to write

int en=(ind-1)/sz;

I checked for some critical values of N. Out of those, none of values of N\le 500 gave RE. The next were couple of cases with N=1000, and I got a RE immediately. Also, @schleppel 's answer might help, though I think there is something more.

done but no use

Well at least the sigsegv is gone.

When you’re stuck try writing a test case generator and compare the output of your program to one of the solutions of the contest that got AC.
When you found a test case that gets you differing output the debugging “fun” can begin. :wink:

And when this doesn’t get you anywhere clean up your code and ask here again. The code you linked is a mess. Give your variables meaningful names, not k, co, fg etc. Use standard c++ and not dirty hacks like variable length arrays (scanf("%d%d",&n,&q);int a[n]; - this is not legal c++).

1 Like

i will keep this things in mind and i will try until i get AC

1 Like