Spoj STPAR

Question Link :- SPOJ.com - Problem STPAR

Can anyone help me out why I am getting SIGSEGV error in my code…??

Try changing the size of array p to 1005 something. I’m not sure but SIGSEGV usually happens due to array out of bounds

yes!
This is an error caused by an invalid memory reference or segmentation fault. The most common causes are accessing an array element out of bounds, or using too much memory.

try different input
5
4 1 5 3 2
5
3 1 2 5 4
5
5 3 2 1 4
10
1 2 10 5 4 3 7 6 8 9
10
1 2 10 5 4 3 9 8 7 6
5
3 5 2 4 1
5
1 2 4 3 5
4
4 2 3 1
no
yes
yes
yes
yes
no
yes
no

Bro.!!
I previously tried this problem by creating an array Dynamically. That time also I was getting SIGSEGV error.
See this Solution:- EigRiP - Online C++0x Compiler & Debugging Tool - Ideone.com

Mate…!!
I know SIGSEGV error is caused due to segmentation fault. But please help me out why in this code, I am getting this error.

Bro !!!
Did my code gave you these outputs …??

My code will stop only when I give value of n as 0 or else it will run infinitely.
Your inputs doesn’t include 0.

please help me
I am getting wrong answer
here’s the link to my solution