Language: C++

#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>

#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <random>
#include <complex>
#include <utility>
#include <tuple>
#include <memory>

#include <array>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <csignal>
#include <cstdint>
#include <cstddef>

#ifdef ONLINE_JUDGE
#define NDEBUG
#endif
#include <cassert>
#include <stdexcept>
#include <exception>

// << pair
template <typename T1, typename T2>
std::ostream&operator<<(std::ostream&os,const std::pair<T1,T2>&p){return os<<"("<<p.first<<", "<<p.second<<")";}
// << container
template <typename C>
std::ostream&_debug_go(std::ostream&os,const C&v) {bool first=true;os<<"[";for(auto i:v){if(!first)os<<", ";os<<i;first=false;}return os<<"]";}
// << {vector, set, map} delegating to _debug_go
template<typename T> std::ostream&operator<<(std::ostream&os,const std::vector<T>&v){return _debug_go(os, v);}
template<typename T> std::ostream&operator<<(std::ostream&os,const std::set<T>&v){return _debug_go(os, v);}
template<typename T1, typename T2> std::ostream&operator<<(std::ostream&os,const std::map<T1,T2>&v){return _debug_go(os, v);}
struct Debugger{template<typename T>Debugger&operator,(const T&v){std::cerr<<v<<" "; return *this;}} dbg;
#ifndef NDEBUG
#define debug(args...) do {dbg,args; cerr << "\n";} while(0)
#else
#define debug(args...)
#endif

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ITER(i, s, e) for (auto i((s)); i != (e); ++i)
#define IT(i, c) ITER(i, (c).begin(), (c).end())

using namespace std;

using ui = uint32_t;
using ll = int64_t;
using ull = uint64_t;
template <typename T = int> using Pt = complex<T>;

template <typename T>
T cross(const Pt<T>& a, const Pt<T>& b) { return a.real() * b.imag() - a.imag() * b.real(); }

template <typename T>
bool cmpPt(const Pt<T>& a, const Pt<T>& b) {
    return a.real() < b.real() || (a.real() == b.real() && a.imag() < b.imag());
}
// END TEMPLATE

vector<int> runSlow(int N, ll M, const vector<int>& A) {
    debug(N, M);
    vector<int> ans;
    set<int> s;
    REP(i, M) {
        debug(i, ans, A[i % N]);
        if (!s.insert(A[i % N]).second) {
            while (ans.back() != A[i % N]) s.erase(ans.back()), ans.pop_back();
            s.erase(ans.back()), ans.pop_back();
        } else {
            ans.push_back(A[i % N]);
        }
    }
    return ans;
}

vector<int> solveSlow(int N, ll K, const vector<int>& A) {
    return runSlow(N, N*K, A);
}

/* old incorrect code
vector<int> solve(int N, ll K, const vector<int>& A) {
    map<int, vector<int>> pos;
    REP(i, N) pos[A[i]].push_back(i);
    map<int, ll> seen;
    ll cur = 0;
    ll m = 0;
    while (true) {
        //debug(cur, m);
        if (!seen.insert({cur, m}).second) break;
        ++m;
        int next;
        if (cur == pos[A[cur]].back()) {
            next = pos[A[cur]].front();
            m += N-cur+next;
        } else {
            next = *upper_bound(pos[A[cur]].begin(), pos[A[cur]].end(), cur);
            m += next-cur;
        }
        cur = next+1;
        if (cur == N) cur = 0;
    }
    ll k = seen[cur];
    m -= k;
    //ll M = N*K; // TODO too big
    //M = M < k ? M : (M - k) % m + k;
    ll M = N*(K % m) - (k % m);
    if (M < 0) M += m;
    M = M % m + k;
    //debug(N, K, A, m, k, M);
    //debug(solveSlow(N, K, A));

    ll curm = 0;
    cur = 0;
    while (true) {
        //debug("cur:", cur, curm);
        ll nextm, next;
        if (cur == pos[A[cur]].back()) {
            next = pos[A[cur]].front();
            nextm = curm+1 + N-cur+next;
        } else {
            next = *upper_bound(pos[A[cur]].begin(), pos[A[cur]].end(), cur);
            nextm = curm+1 + next-cur;
        }
        //debug("next:", next, nextm);
        if (nextm >= M) {
            vector<int> ans;
            set<int> s;
            //debug(curm, "->", M);
            REP(_, M-curm) {
                //debug("pos:", cur);
                if (!s.insert(A[cur]).second) {
                    while (ans.back() != A[cur]) s.erase(ans.back()), ans.pop_back();
                    s.erase(ans.back()), ans.pop_back();
                } else ans.push_back(A[cur++]);
                if (cur == N) cur = 0;
            }
            return ans;
        }
        curm = nextm;
        cur = next+1;
        if (cur == N) cur = 0;
    }
    assert(false);
    return vector<int>{};

    //return runSlow(N, M, A);
}
*/

template <typename K>
struct custom_hash {
    size_t operator()(const K& x) const;
};

template <>
struct custom_hash<uint64_t> {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

template <>
struct custom_hash<int> {
    custom_hash<uint64_t> h;
    size_t operator()(const int& x) const {
        return h(uint64_t(x));
    }
};

template <typename K, typename V> using munordered_map = unordered_map<K, V, custom_hash<K>>;

struct Solver {
    const int N;
    const vector<int> A;

    munordered_map<int, vector<int>> pos;
    int per;
    ll m;
    vector<int> sh;

    Solver(int N, const vector<int>& A) : N(N), A(A), sh(N) {
        REP(i, N) pos[A[i]].push_back(i);
        for (const auto& [a, p] : pos) {
            REP(i, int(p.size())-1) {
                sh[p[i]] = p[i+1] - p[i] + 1;
            }
            sh[p.back()] = N - p.back() + p[0] + 1;
        }
        per = 0;
        m = 0;
        int cur = 0;
        do {
            ++per;
            m += sh[cur];
            cur = next(cur);
        } while (cur != 0);
    }

    int next(int i) const {
        assert(0 <= i && i < N);
        i += sh[i];
        while (i >= N) i -= N;
        assert(0 <= i && i < N);
        return i;
    }

    vector<int> query(ll K) const {
        ll d = 0;
        int cur = 0;
        K %= m;
        int x = 0;
        while (d + sh[cur] < N*K%m) {
            d += sh[cur];
            cur = next(cur);
            ++x;
            assert(x <= per);
        }
        vector<int> ans;
        set<int> s;
        REP(_, N*K%m - d) {
            if (!s.insert(A[cur]).second) {
                while (ans.back() != A[cur]) s.erase(ans.back()), ans.pop_back();
                s.erase(ans.back()), ans.pop_back();
            } else {
                s.insert(A[cur]), ans.push_back(A[cur]);
            }
            ++cur;
            if (cur == N) cur = 0;
        }
        return ans;
    }
};

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

    int N; ll K; cin >> N >> K;
    vector<int> A(N);
    for (int& a : A) cin >> a;
    Solver s(N, A);
    auto ans = s.query(K);
    for (int a : ans) cout << a << " ";
    cout << '\n';

    return 0;
}


Compiler output:
a.cc: In member function 'size_t custom_hash<long unsigned int>::operator()(uint64_t) const':
a.cc:186:46: error: 'chrono' has not been declared
  186 |         static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
      |                                              ^~~~~~