terminated due to timeout
/*Help me find why the program is terminated due to timeout, and correction needed.*/ #include <iostream> using namespace std; int main() { int N,Q,ndx,ndx2; int lastAnswer=0; int q,x,y,z=0,key=0; cin>>N; cin>>Q; int seqList[N][N]; //initialize the seqList to 0. for(int l=0;l<N;l++) { for(int m=0;m<N;m++) { seqList[l][m]=0; } } //Taking the Q quiries, and performing the corresponding operations. for(int i=0;i<Q;i++) { cin>>q; cin>>x; cin>>y; if(q==1) { /*op. 1*/ ndx=(x^lastAnswer)%N; /*op. 2*/ for(int j=0;j<N;j++) { if(seqList[ndx][j]==0) { seqList[ndx][j]=y; break; } j++; } } else { /*op. 1*/ ndx=(x^lastAnswer)%N; /*op. 2*/ while(seqList[ndx][z]!=0) { key++; } ndx2=y%key; cout<<seqList[ndx][ndx2]<<endl; lastAnswer=seqList[ndx][ndx2]; /*op. 3*/ cout<<lastAnswer<<endl; } }