出栈的模拟
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<set>
#include<stack>
using namespace std;
stack<int> s;
int m, n, k;
int main(){
cin>>m>>n>>k;
for(int i = 0; i < k; i++){
int cur = 1;
bool flag = true;
while(!s.empty()) s.pop();
for(int j = 0; j < n; j++){
int temp;
scanf("%d",&temp);
if(flag){
if(cur > temp){
if(s.top() != temp){
flag = false;
}
}
else{
while(cur <= temp){
s.push(cur);
if(s.size() > m){
flag = false;
// break;
}
cur++;
}
}
s.pop();
}
}
if(flag){
printf("YES\n");
}
else{
printf("NO\n");
}
}
return 0;
}