//1.若scan到a时为空栈,栈顶元素设为0
//2.若数字a>栈顶元素,<=a的remain全部入栈,若栈满则停止。
//3.若a=新的栈顶元素,出栈;否则NO
#include <stdio.h>
typedef struct
{
int array[1000];
int index;
}STACK;
int main()
{
int M;//the maximum capacity of the stack
int N;//the length of push sequence
int K;//the number of pop sequences to be checked
STACK stack1;
int i,j;
int flag;
int min;//还没有push进stack的最小值
scanf("%d %d %d",&M,&N,&K);
for(i=0;i<K;i++)//k个测试用例
{
int array[1000];
int k;
int topnum;
for(j=0;j<N;j++)//n个测试数据
scanf("%d",&array[j]);
flag=1;
min=1;
stack1.index=-1;
for(j=0;j<N;j++)//扫描本次测试用例的n个测试数据
{
if(stack1.index==-1) //流程1.
topnum=0;
else
topnum=stack1.array[stack1.index];
if(array[j]>topnum) //流程2.
{
for(k=array[j];k>=min;k--)
{
if(stack1.index < M-1)
stack1.index++;
else
break;
stack1.array[stack1.index]=k;
}
min=array[j]+1;
}
topnum=stack1.array[stack1.index];
if(array[j]==topnum) //流程3.
stack1.index--;
else
{
flag=0;
break;
}
}
if(flag) //输出
printf("YES");
else
printf("NO");
if(i<K-1)
printf("\n");
}
return 0;
}
}