fork download
  1. /**
  2.  * author: orzvanh14 ( Độc cô cầu đặc )
  3.  * created: 18.04.2026 03:56:02
  4.  * too lazy to update time
  5. **/
  6. // i wants to take ioi
  7. //binhtinhtutinkhongcaycunhungmotkhikhongcontutinnualatuyetvong
  8. #include <bits/stdc++.h>
  9.  
  10. using namespace std;
  11.  
  12. #define int long long
  13. #define nn "\n"
  14. #define pi pair<int, int>
  15. #define ti tuple<int, int, int>
  16. #define fi first
  17. #define se second
  18. #define lb lower_bound
  19. #define ub upper_bound
  20. #define eb emplace_back
  21. #define pb push_back
  22. #define TASK " "
  23.  
  24. #define ms(a, x) memset(a, x, sizeof(a))
  25. #define all(a) a.begin(), a.end()
  26. #define All(a, n) a + 1, a + 1 + n
  27.  
  28. #define LOG 19
  29.  
  30. const int INF = 1e18;
  31. const int N = 1e5 + 5;
  32. const int maxn = 100 + 5;
  33. const int mod = 1e9 + 7;
  34.  
  35.  
  36. struct node{
  37. int kc, u;
  38. bool operator<(const node& other) const {
  39. return kc > other.kc;
  40. }
  41. };
  42. int n;
  43. void nhap(){
  44.  
  45. }
  46. void solve(){
  47. while(cin >> n){
  48. if(n == 0) return;
  49. vector<int> a(n + 5);
  50. for(int i = 1; i <= n; i++){
  51. cin >> a[i];
  52. }
  53. stack<int> st;
  54. int cur = 1;
  55. bool ok = 1;
  56. for(int i = 1; i <= n; i++){
  57. if(a[i] != cur){
  58. st.push(a[i]);
  59. }
  60. else{
  61. cur++;
  62. }
  63. }
  64. while(!st.empty()){
  65. int x = st.top();
  66. st.pop();
  67. if(x == cur){
  68. cur++;
  69. }
  70. else{
  71. ok = 0;
  72. }
  73. }
  74. if(!ok){
  75. cout << "no" << nn;
  76. }
  77. else cout << "yes" << nn;
  78. }
  79. }
  80. signed main(){
  81. // freopen("wormsort.in", "r", stdin);
  82. // freopen("wormsort.out", "w", stdout);
  83. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  84. nhap();
  85. solve();
  86. return 0;
  87. }
  88.  
Success #stdin #stdout 0.01s 5316KB
stdin
5
5 1 2 4 3 
0

stdout
yes