This commit is contained in:
HuangHai
2025-08-30 18:35:01 +08:00
commit 1f397eca87
6258 changed files with 1487241 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, target;
stack<int> st;
cin >> n;
int cur = 1; // 当前待入栈数字
for (int i = 0; i < n; i++) {
cin >> target; // 读取目标出站值
// 当前目标值未入栈,持续入栈直到包含目标值
while (cur <= target)
st.push(cur++);
// 栈顶匹配则出栈
if (!st.empty() && st.top() == target) {
st.pop();
} else {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
}