Language: C++

#include <iostream>
#include <vector>

int main(){
  int n, m;
  cin >> n >> m;
  int q;
  cin >> q;
  vector<int> a(q);
  for(int i = 0; i < q; i++){
    cin >> a[i];
    a[i]--;
  }

  vector<int> b(m);
  vector<int> pos(m);
  vector<int> freq(m + 1);
  
  int known = 0;
  for(int it = q - 1; it >= 0; it--){
    int i = a[it];
    if(pos[i] = -1){
      b[known] = i;
      pos[i] = known;
      freq[known]--;
      known++;
      freq[known]++;
      continue;
    }
    if(freq[pos[i]] > 0){
      freq[pos[i]]--;
      freq[pos[i] + 1]++;
    }
  }
  
  int first = -1;
  for(int i = 0; i <= m; i++){
    if(freq[i] !=0){
        first = -1;
        break;
    }
  }
  
  vector<int> all;
  for(int i = first; i < known; i++){
     all.push_back(b[i]);
  }
  for(int i = 0; i < m; i++){
    if(pos[i] == -1){
      all.push_back(i);
    }
  }
  
  for(int i = first; i < known; i++){
    if(all[i - first] != a[i]){
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}

Compiler output:
a.cc: In function 'int main()':
a.cc:6:3: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
    6 |   cin >> n >> m;
      |   ^~~
      |   std::cin
In file included from a.cc:1:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:9:3: error: 'vector' was not declared in this scope
    9 |   vector<int> a(q);
      |   ^~~~~~
a.cc:9:3: note: suggested alternatives:
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_vector.h:428:11: note:   'std::vector'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
/usr/include/c++/14/vector:93:13: note:   'std::pmr::vector'
   93 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
a.cc:9:10: error: expected primary-expression before 'int'
    9 |   vector<int> a(q);
      |          ^~~
a.cc:11:12: error: 'a' was not declared in this scope
   11 |     cin >> a[i];
      |            ^
a.cc:15:10: error: expected primary-expression before 'int'
   15 |   vector<int> b(m);
      |          ^~~
a.cc:16:10: error: expected primary-expression before 'int'
   16 |   vector<int> pos(m);
      |          ^~~
a.cc:17:10: error: expected primary-expression before 'int'
   17 |   vector<int> freq(m + 1);
      |          ^~~
a.cc:21:13: error: 'a' was not declared in this scope
   21 |     int i = a[it];
      |             ^
a.cc:22:8: error: 'pos' was not declared in this scope
   22 |     if(pos[i] = -1){
      |        ^~~
a.cc:23:7: error: 'b' was not declared in this scope
   23 |       b[known] = i;
      |       ^
a.cc:25:7: error: 'freq' was not declared in this scope; did you mean 'free'?
   25 |       freq[known]--;
      |       ^~~~
      |       free
a.cc:30:8: error: 'freq' was not declared in this scope; did you mean 'free'?
   30 |     if(freq[pos[i]] > 0){
      |        ^~~~
      |        free
a.cc:30:13: error: 'pos' was not declared in this scope
   30 |     if(freq[pos[i]] > 0){
      |             ^~~
a.cc:38:8: error: 'freq' was not declared in this scope; did you mean 'free'?
   38 |     if(freq[i] !=0){
      |        ^~~~
      |        free
a.cc:44:10: error: expected primary-expression before 'int'
   44 |   vector<int> all;
      |          ^~~
a.cc:46:6: error: 'all' was not declared in this scope; did you mean 'atoll'?
   46 |      all.push_back(b[i]);
      |      ^~~
      |      atoll
a.cc:46:20: error: 'b' was not declared in this scope
   46 |      all.push_back(b[i]);
      |                    ^
a.cc:49:8: error: 'pos' was not declared in this scope
   49 |     if(pos[i] == -1){
      |        ^~~
a.cc:50:7: error: 'all' was not declared in this scope; did you mean 'atoll'?
   50 |       all.push_back(i);
      |       ^~~
      |       atoll
a.cc:55:8: error: 'all' was not declared in this scope; did you mean 'atoll'?
   55 |     if(all[i - first] != a[i]){
      |        ^~~
      |        atoll
a.cc:55:26: error: 'a' was not declared in this scope
   55 |     if(all[i - first] != a[i]){
      |                          ^
a.cc:56:7: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   56 |       cout << "No";
      |       ^~~~
      |       std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:60:3: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   60 |   cout << "Yes";
      |   ^~~~
      |   std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~