Language: C++

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

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 && back[l] != -1) {
                p=back[l]-1;
                back[l] = -1;
                //cerr << "p = " << p << endl;
            } else {
                if (p+1 >= sz(cur)) cur.pb(l);
                else cur[p+1] = l;
                ++p;

                if (backinv.find(p) != backinv.end() && back.find(backinv[p]) != back.end() && back[backinv[p]] == p) {
                    //cerr << "erasing " << backinv[p] << endl;
                    back[backinv[p]] = -1;
                }

                if (back.find(l) != back.end() && backinv.find(back[l]) != backinv.end()) backinv[back[l]] = -1;
                
                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[l] = -1;
                //cerr << "p = " << p << endl;
            } else {
                if (p+1 >= sz(cur)) cur.pb(l);
                else cur[p+1] = l;
                ++p;

    
                if (backinv.find(p) != backinv.end() && back.find(backinv[p]) != back.end() && back[backinv[p]] == p) {
                    //cerr << "erasing " << backinv[p] << endl;
                    back[backinv[p]] = -1;
                }

                if (back.find(l) != back.end() && backinv.find(back[l]) != backinv.end()) backinv[back[l]] = -1;
                
                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 && back[l] != -1) {
      |                      ^~~~~
a.cc:92:22: error: 'class __gnu_pbds::gp_hash_table<long long int, int>' has no member named 'count'
   92 |             if (back.count(l) && back[l] <= p) {
      |                      ^~~~~