#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 9;
int arr[N];
int n, m, k;
bool solve()
{
stack<int> st;
int p = 1, mx = 0;
for (int i = 1; i <= n; i++)
{
if (arr[i] == p)
{
p++;
continue;
}
else
{
if (st.size())
{
while (st.size())
{
if (st.top() == p)
{
p++;
st.pop();
}
else
break;
}
if (arr[i] == p)
{
p++;
continue;
}
else
{
st.push(arr[i]);
mx = max((int)st.size(), mx);
if (mx > m)
return 0;
}
}
else
{
st.push(arr[i]);
mx = max((int)st.size(), mx);
if (mx > m)
return 0;
}
}
}
while (st.size())
{
if (st.top() == p)
{
p++;
st.pop();
}
else
break;
}
if (st.size())
return 0;
return 1;
}
int main()
{
cin >> n >> m >> k;
while (k--)
{
for (int i = 1; i <= n; i++)
{
cin >> arr[i];
}
if (solve())
{
cout << "YES\n";
}
else
cout << "NO\n";
}
return 0;
}
L2-032 彩虹瓶 (25 分)(栈
最新推荐文章于 2024-04-30 09:28:48 发布