fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define fr first
  4. #define endl "\n"
  5. #define sc second
  6. #define sz(x) (int) x.size()
  7. #define pb push_back
  8. #define all(x) x.begin(), x.end()
  9.  
  10. using namespace std;
  11. using pii = pair<ll, ll>;
  12. using tii = tuple<ll, ll, ll>;
  13. string printBin(ll m) { string a = ""; for(int i=63; i>=0; i--) { if(m & (1<<i)) {a += '1';} else {a += '0';} } return a; }
  14.  
  15. int main() {
  16. ios::sync_with_stdio(0); cin.tie(0);
  17.  
  18. int n;
  19.  
  20. while(cin >> n) {
  21. if(n == 0) break;
  22.  
  23. int ai;
  24.  
  25. while(cin >> ai) {
  26. if(ai == 0) break;
  27.  
  28. int cur = n;
  29. vector<int> a(n);
  30. a[0] = ai;
  31. for(int i=1; i<n; i++) cin >> a[i];
  32.  
  33. stack<int> aux;
  34.  
  35. for(int i=n-1; i>=0; i--) {
  36. aux.push(a[i]);
  37. while(!aux.empty() && aux.top() == cur) {
  38. cur--;
  39. aux.pop();
  40. }
  41. }
  42.  
  43. bool ok = true;
  44. while(!aux.empty()) {
  45. auto pi = aux.top();
  46. aux.pop();
  47.  
  48. if(pi == cur) {
  49. //cout << cur << endl;
  50. cur--;
  51. } else {
  52. ok = false;
  53. break;
  54. }
  55. }
  56. if(ok) cout << "Yes" << endl;
  57. else cout << "No" << endl;
  58. }
  59. cout << endl;
  60. }
  61. }
Success #stdin #stdout 0s 544KB
stdin
Standard input is empty
stdout
Standard output is empty