Language: C++

#include<bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define f first
#define s second 
#define sz(s) (int)s.size()
#define int long long
#define all(s) s.begin(), s.end()
#define forn(i, x, y) for(int i = x; i <= y; i++)
#define forev(i, y, x) for(int i = y; i >= x; i--)

using namespace std;

const int maxn = (int)4e5 + 100;
const int mod = (int)1e9 + 7;
const int P = (int)1e6 + 7;
const int inf = (int)1e9 + 7;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef long double ld;

int n, k, a[maxn], nxt[maxn], lst[maxn], was[maxn], f[maxn], up[maxn][66];

int convert(int x){
  return (x - 1) % n + 1;
}
main () {
  cin >> n >> k;
  forn(i, 1, n){
    cin >> a[i];
    if(!f[a[i]]) f[a[i]] = i;
  }
  forev(i, n, 1){
    if(!lst[a[i]]){
      nxt[i] = n - i + 1 + f[a[i]];
    }else{
      nxt[i] = lst[a[i]] - i + 1;
    }
    lst[a[i]] = i;
  }
  forn(i, 1, n) up[i][0] = nxt[i];
  forn(lvl, 1, 60){
    forn(i, 1, n){
      int x = convert(up[i][lvl - 1] + i);
      up[i][lvl] = min(20000000000000000001, up[i][lvl - 1] + up[x][lvl - 1]);
      //cout << i << " " << lvl << " " << up[i][lvl] << " " << x << " " << endl;
    }
  }
  int cur = 1, pos = 1;
  forev(i, 60, 0){
    if(cur + up[pos][i] <= n * k){
      cur += up[pos][i];
      pos = convert(pos + up[pos][i]);
    }
  }
  vi v;
  forn(i, cur, n * k){
    int x = a[convert(i)];
    if(was[x]){
      while(v.back() != x) v.pop_back();
      v.pop_back();
      was[x] = 0;
    }else{
      was[x] = 1;
      v.pb(x);
    }
  }
  for(auto x : v) cout << x << " ";
}

Compiler output:
a.cc:49:24: warning: integer constant is too large for its type
   49 |       up[i][lvl] = min(20000000000000000001, up[i][lvl - 1] + up[x][lvl - 1]);
      |                        ^~~~~~~~~~~~~~~~~~~~
a.cc:31:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   31 | main () {
      | ^~~~
a.cc: In function 'int main()':
a.cc:49:23: error: no matching function for call to 'min(long int, long long int)'
   49 |       up[i][lvl] = min(20000000000000000001, up[i][lvl - 1] + up[x][lvl - 1]);
      |                    ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:49:23: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
   49 |       up[i][lvl] = min(20000000000000000001, up[i][lvl - 1] + up[x][lvl - 1]);
      |                    ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:49:23: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   49 |       up[i][lvl] = min(20000000000000000001, up[i][lvl - 1] + up[x][lvl - 1]);
      |                    ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~