Language: C++

#include <bits/stdc++.h>
#include <bits/extc++.h> /** keep-include */

using namespace std;

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define PI (acos(-1))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))

#define MAXN 1123456
#define MOD 1000000007

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
typedef vector<vi> vvi;

__gnu_pbds::gp_hash_table<ll,int> back;
__gnu_pbds::gp_hash_table<ll,int> backinv;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    ll n, k;
    cin >> n >> k;

    vi cur;

    vi a(n);
    rep(i,0,n) cin >> a[i];

    ll p=-1;

    ll cyc = 0;

    rep(i,1,k+1) {
        rep(j,0,n) {
            ll l = a[j];
            //cerr << "l: " << l << endl;
            if (back.count(l) && back[l] <= p) {
                p=back[l]-1;
                back.erase(back.find(l));
                //cerr << "p = " << p << endl;
            } else {
                if (p+1 >= sz(cur)) cur.pb(l);
                else cur[p+1] = l;
                ++p;

                if (backinv.count(p) && back.count(backinv[p]) && back[backinv[p]] == p) {
                    //cerr << "erasing " << backinv[p] << endl;
                    back.erase(back.find(backinv[p]));
                }

                if (back.count(l) && backinv.count(back[l])) backinv.erase(backinv.find(back[l]));
                
                back[l]=p;
                //cerr << "back[" << l << "] = " << p << endl;
                backinv[p]=l;
            }
        }
        if (p == -1) {
            cyc = i;   
            break;
        }

        if (i == k) {
            rep(u,0,p+1) cout << cur[u] << " " ;
            cout << endl;
            return 0;
        }
        //getchar();
    }

    if (cyc)
    k %= cyc;

    rep(i,1,k+1) {
        rep(j,0,n) {
            ll l = a[j];
            //cerr << "l: " << l << endl;
            if (back.count(l) && back[l] <= p) {
                p=back[l]-1;
                back.erase(back.find(l));
                //cerr << "p = " << p << endl;
            } else {
                if (p+1 >= sz(cur)) cur.pb(l);
                else cur[p+1] = l;
                ++p;

                if (backinv.count(p) && back.count(backinv[p]) && back[backinv[p]] == p) {
                    //cerr << "erasing " << backinv[p] << endl;
                    back.erase(back.find(backinv[p]));
                }

                if (back.count(l) && backinv.count(back[l])) backinv.erase(backinv.find(back[l]));
                
                back[l]=p;
                //cerr << "back[" << l << "] = " << p << endl;
                backinv[p]=l;
            }
        }

        if (i == k) {
            rep(u,0,p+1) cout << cur[u] << " " ;
            cout << endl;
            return 0;
        }
        //getchar();
    }

}


Compiler output:
a.cc: In function 'int main()':
a.cc:51:22: error: 'class __gnu_pbds::gp_hash_table<long long int, int>' has no member named 'count'
   51 |             if (back.count(l) && back[l] <= p) {
      |                      ^~~~~
a.cc:53:37: error: cannot convert '__gnu_pbds::detail::gp_ht_map<long long int, int, std::tr1::hash<long long int>, std::equal_to<long long int>, std::allocator<char>, false, __gnu_pbds::direct_mask_range_hashing<>, __gnu_pbds::linear_probe_fn<long unsigned int>, __gnu_pbds::hash_standard_resize_policy<__gnu_pbds::hash_exponential_size_policy<>, __gnu_pbds::hash_load_check_resize_trigger<>, false, long unsigned int> >::point_iterator' {aka '__gnu_pbds::detail::gp_ht_map<long long int, int, std::tr1::hash<long long int>, std::equal_to<long long int>, std::allocator<char>, false, __gnu_pbds::direct_mask_range_hashing<>, __gnu_pbds::linear_probe_fn<long unsigned int>, __gnu_pbds::hash_standard_resize_policy<__gnu_pbds::hash_exponential_size_policy<>, __gnu_pbds::hash_load_check_resize_trigger<>, false, long unsigned int> >::point_iterator_'} to '__gnu_pbds::detail::gp_ht_map<long long int, int, std::tr1::hash<long long int>, std::equal_to<long long int>, std::allocator<char>, false, __gnu_pbds::direct_mask_range_hashing<>, __gnu_pbds::linear_probe_fn<long unsigned int>, __gnu_pbds::hash_standard_resize_policy<__gnu_pbds::hash_exponential_size_policy<>, __gnu_pbds::hash_load_check_resize_trigger<>, false, long unsigned int> >::key_const_reference' {aka 'const long long int&'}
   53 |                 back.erase(back.find(l));
      |                            ~~~~~~~~~^~~
      |                                     |
      |                                     __gnu_pbds::detail::gp_ht_map<long long int, int, std::tr1::hash<long long int>, std::equal_to<long long int>, std::allocator<char>, false, __gnu_pbds::direct_mask_range_hashing<>, __gnu_pbds::linear_probe_fn<long unsigned int>, __gnu_pbds::hash_standard_resize_policy<__gnu_pbds::hash_exponential_size_policy<>, __gnu_pbds::hash_load_check_resize_trigger<>, false, long unsigned int> >::point_iterator {aka __gnu_pbds::detail::gp_ht_map<long long int, int, std::tr1::hash<long long int>, std::equal_to<long long int>, std::allocator<char>, false, __gnu_pbds::direct_mask_range_hashing<>, __gnu_pbds::linear_probe_fn<long unsigned int>, __gnu_pbds::hash_standard_resize_policy<__gnu_pbds::hash_exponential_size_policy<>, __gnu_pbds::hash_load_check_resize_trigger<>, false, long unsigned int> >::point_iterator_}
In file included from /usr/include/c++/14/ext/pb_ds/detail/gp_hash_table_map_/gp_ht_map_.hpp:701,
                 from /usr/include/c++/14/ext/pb_ds/detail/container_base_dispatch.hpp:72,
                 from /usr/include/c++/14/ext/pb_ds/assoc_container.hpp:48,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/extc++.h:74,
                 from a.cc:2:
/usr/include/c++/14/ext/pb_ds/detail/gp_hash_table_map_/erase_fn_imps.hpp:98:27: note:   initializing argument 1 of 'bool __gnu_pbds::detail::gp_ht_map<Key, Mapped, Hash_Fn, Eq_Fn, _Alloc, Store_Hash, Comb_Probe_Fn, Probe_Fn, Resize_Policy>::erase(key_const_reference) [with Key = long long int; Mapped = int; Hash_Fn = std::tr1::hash<long long int>; Eq_Fn = std::equal_to<long long int>; _Alloc = std::allocator<char>; bool Store_Hash = false; Comb_Probe_Fn = __gnu_pbds::direct_mask_range_hashing<>; Probe_Fn = __gnu_pbds::linear_probe_fn<long unsigned int>; Resize_Policy = __gnu_pbds::hash_standard_resize_policy<__gnu_pbds::hash_exponential_size_policy<>, __gnu_pbds::hash_load_check_resize_trigger<>, false, long unsigned int>; key_const_reference = const long long int&]'
   98 | erase(key_const_reference r_key)
      |       ~~~~~~~~~~~~~~~~~~~~^~~~~
a.cc:60:29: error: 'class __gnu_pbds::gp_hash_table<long long int, int>' has no member named 'count'
   60 |                 if (backinv.count(p) && back.count(backinv[p]) && back[backinv[p]] == p) {
      |                             ^~~~~
a.cc:60:46: error: 'class __gnu_pbds::gp_hash_table<long long int, int>' has no member named 'count'
   60 |                 if (backinv.count(p) && back.count(backinv[p]) && back[backinv[p]] == p) {
      |                                              ^~~~~
a.cc:62:41: error: cannot convert '__gnu_pbds::detail::gp_ht_map<long long int, int, std::tr1::hash<long long int>, std::equal_to<long long int>, std::allocator<char>, false, __gnu_pbds::direct_mask_range_hashing<>, __gnu_pbds::linear_probe_fn<long unsigned int>, __gnu_pbds::hash_standard_resize_policy<__gnu_pbds::hash_exponential_size_policy<>, __gnu_pbds::hash_load_check_resize_trigger<>, false, long unsigned int> >::point_iterator' {aka '__gnu_pbds::detail::gp_ht_map<long long int, int, std::tr1::hash<long long int>, std::equal_to<long long int>, std::allocator<char>, false, __gnu_pbds::direct_mask_range_hashing<>, __gnu_pbds::linear_probe_fn<long unsigned int>, __gnu_pbds::hash_standard_resize_policy<__gnu_pbds::hash_exponential_size_policy<>, __gnu_pbds::hash_load_check_resize_trigger<>, false, long unsigned int> >::point_iterator_'} to '__gnu_pbds::detail::gp_ht_map<long long int, int, std::tr1::hash<long long int>, std::equal_to<long long int>, std::allocator<char>, false, __gnu_pbds::direct_mask_range_hashing<>, __gnu_pbds::linear_probe_fn<long unsigned int>, __gnu_pbds::hash_standard_resize_policy<__gnu_pbds::hash_exponential_size_policy<>, __gnu_pbds::hash_load_check_resize_trigger<>, false, long unsigned int> >::key_const_reference' {aka 'const long long int&'}
   62 |                     back.erase(back.find(backinv[p]));
      |                                ~~~~~~~~~^~~~~~~~~~~~
      |                                         |
      |                                         __gnu_pbds::detail::gp_ht_map<long long int, int, std::tr1::hash<long long int>, std::equal_to<long long int>, std::allocator<char>, false, __gnu_pbds::direct_mask_range_hashing<>, __gnu_pbds::linear_probe_fn<long unsigned int>, __gnu_pbds::hash_standard_resize_policy<__gnu_pbds::hash_exponential_size_policy<>, __gnu_pbds::hash_load_check_resize_trigger<>, false, long unsigned int> >::point_iterator {aka __gnu_pbds::detail::gp_ht_map<long long int, int, std::tr1::hash<long long int>, std::equal_to<long long int>, std::allocator<char>, false, __gnu_pbds::direct_mask_range_hashing<>, __gnu_pbds::linear_probe_fn<long unsigned int>, __gnu_pbds::hash_standard_resize_policy<__gnu_pbds::hash_exponential_size_policy<>, __gnu_pbds::hash_load_check_resize_trigger<>, false, long unsigned int> >::point_iterator_}
/usr/include/c++/14/ext/pb_ds/detail/gp_hash_table_map_/erase_fn_imps.hpp:98:27: note:   initializing argument 1 of 'bool __gnu_pbds::detail::gp_ht_map<Key, Mapped, Hash_Fn, Eq_Fn, _Alloc, Store_Hash, Comb_Probe_Fn, Probe_Fn, Resize_Policy>::erase(key_const_reference) [with Key = long long int; Mapped = int; Hash_Fn = std::tr1::hash<long long int>; Eq_Fn = std::equal_to<long long int>; _Alloc = std::allocator<char>; bool Store_Hash = false; Comb_Probe_Fn = __gnu_pbds::direct_mask_range_hashing<>; Probe_Fn = __gnu_pbds::linear_probe_fn<long unsigned int>; Resize_Policy = __gnu_pbds::hash_standard_resize_policy<__gnu_pbds::hash_exponential_size_policy<>, __gnu_pbds::hash_load_check_resize_trigger<>, false, long unsigned int>; key_const_reference = const long long int&]'
   98 | erase(key_const_reference r_key)
      |       ~~~~~~~~~~~~~~~~~~~~^~~~~
a.cc:65:26: error: 'class __gnu_pbds::gp_hash_table<long long int, int>' has no member named 'count'
   65 |                 if (back.count(l) && backinv.count(back[l])) backinv.erase(backinv.find(back[l]));
      |                          ^~~~~
a.cc:65:46: error: 'class __gnu_pbds::gp_hash_table<long long int, int>' has no member named 'count'
   65 |                 if (back.count(l) && backinv.count(back[l])) backinv.erase(backinv.find(back[l]));
      |                                              ^~~~~
a.cc:65:88: error: cannot convert '__gnu_pbds::detail::gp_ht_map<long long int, int, std::tr1::hash<long long int>, std::equal_to<long long int>, std::allocator<char>, false, __gnu_pbds::direct_mask_range_hashing<>, __gnu_pbds::linear_probe_fn<long unsigned int>, __gnu_pbds::hash_standard_resize_policy<__gnu_pbds::hash_exponential_size_policy<>, __gnu_pbds::hash_load_check_resize_trigger<>, false, long unsigned int> >::point_iterator' {aka '__gnu_pbds::detail::gp_ht_map<long long int, int, std::tr1::hash<long long int>, std::equal_to<long long int>, std::allocator<char>, false, __gnu_pbds::direct_mask_range_hashing<>, __gnu_pbds::linear_probe_fn<long unsigned int>, __gnu_pbds::hash_standard_resize_policy<__gnu_pbds::hash_exponential_size_policy<>, __gnu_pbds::hash_load_check_resize_trigger<>, false, long unsigned int> >::point_iterator_'} to '__gnu_pbds::detail::gp_ht_map<long long int, int, std::tr1::hash<long long int>, std::equal_to<long long int>, std::allocator<char>, false, __gnu_pbds::direct_mask_range_hashing<>, __gnu_pbds::linear_probe_fn<long unsigned int>, __gnu_pbds::hash_standard_resize_policy<__gnu_pbds::hash_exponential_size_policy<>, __gnu_pbds::hash_load_check_resize_trigger<>, false, long unsigned int> >::key_const_reference' {aka 'const long long int&'}
   65 |                 if (back.count(l) && backinv.count(back[l])) backinv.erase(backinv.find(back[l]));
      |                                                                            ~~~~~~~~~~~~^~~~~~~~~
      |                                                                                        |
      |                                                                                        __gnu_pbds::detail::gp_ht_map<long long int, int, std::tr1::hash<long long int>, std::equal_to<long long int>, std::allocator<char>, false, __gnu_pbds::direct_mask_range_hashing<>, __gnu_pbds::linear_probe_fn<long unsigned int>, __gnu_pbds::hash_standard_resize_policy<__gnu_pbds::hash_exponential_size_policy<>, __gnu_pbds::hash_load_check_resize_trigger<>, false, long unsigned int> >::point_iterator {aka __gnu_pbds::detail::gp_ht_map<long long int, int, std::tr1::hash<long long int>, std::equal_to<long long int>, std::allocator<char>, false, __gnu_pbds::direct_mask_range_hashing<>, _