GM Plants[IOPC1207] SIGSEGV error

The following is the code I have written for www.spoj.com/problems/IOPC1207 Have got 9 SIGSEGV runtime error till now. Please suggest some correction. The code is running fine on Ideone for the example input.

>     #include<iostream>
>     #include<cstdio>
>     using namespace std;
>     int main()
>     {
>         int t,h=0,count=0;
>         scanf("%d",&t);
>         if(t>=1&&t<=10)
>         {
>             int ans[10000];
>             int X,Y,Z,Q;
>             for(int i=0;i<t;i++)
>             {
>                 scanf("%d %d %d %d",&X,&Y,&Z,&Q);
>                 if(X>=1&&X<=100000&&Y>=1&&Y<=100000&&Z>=1&&Y<=100000&&Q>=1&&Q<=5000)
>                 {
>                     int index,low,up,x1,x2,y1,y2,z1,z2,cell[X][Y][Z];
>                     for(int m=0;m<X;m++)
>                     {
>                         for(int n=0;n<Y;n++)
>                         {
>                             for(int p=0;p<Z;p++)
>                                 cell[m][n][p]=0;
>                         }
>                     }
>                     for(int j=0;j<Q;j++)
>                     {
>                         scanf("%d ",&index);
>                         if(index==0)
>                         {
>                             scanf("%d %d",&low,&up);
>                             for(int m=low;m<=up;m++)
>                             {
>                                 for(int n=0;n<Y;n++)
>                                 {
>                                     for(int p=0;p<Z;p++)
>                                         {if(cell[m][n][p]==1)
>                                             cell[m][n][p]=0;
>                                         else if(cell[m][n][p]==0)
>                                             cell[m][n][p]=1;}
>                                 }
>                             }
>                         }
>                         else if(index==1)
>                         {
>                             scanf("%d %d",&low,&up);
>                             for(int n=low;n<=up;n++)
>                             {
>                                 for(int m=0;m<X;m++)
>                                 {
>                                     for(int p=0;p<Z;p++)
>                                         {if(cell[m][n][p]==1)
>                                             cell[m][n][p]=0;
>                                         else if(cell[m][n][p]==0)
>                                             cell[m][n][p]=1;}
>                                 }
>                             }
>                         }
>                         else if(index==2)
>                         {
>                             scanf("%d %d",&low,&up);
>                             for(int p=low;p<=up;p++)
>                             {
>                                 for(int n=0;n<Y;n++)
>                                 {
>                                     for(int m=0;m<X;m++)
>                                        { if(cell[m][n][p]==1)
>                                             cell[m][n][p]=0;
>                                         else if(cell[m][n][p]==0)
>                                             cell[m][n][p]=1;}
>                                 }
>                             }
>                         }
>                         else if(index==3)
>                         {
>                             scanf("%d %d %d %d %d
> %d",&x1,&y1,&z1,&x2,&y2,&z2);
>                             for(int m=x1;m<=x2;m++)
>                             {
>                                 for(int n=y1;n<=y2;n++)
>                                 {
>                                     for(int p=z1;p<=z2;p++)
>                                     {
>                                         if(cell[m][n][p]==1)
>                                             count++;
>                                     }
>                                 }
>                             }         ans[h]=count;
>                             h++;
>                             count=0;
>                         }
>                     }
>                 }
>             }
>             for(int i=0;i<h;i++)
>                 printf("\n%d",ans[i]);
>         }
>     
>         return 0;
>     }
//