Language: C++

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

ll N, K;
ll A[200010];
ll nxt[60][200010], over[60][200010];
ll pre[200010];

int main()
{
    cin >> N >> K;
    for(int i = 0; i < N; i++)cin >> A[i];

    if(N == 1)
    {
        if(K % 2)cout << A[0] << endl;
        else cout << endl;
        return 0;
    }

    for(int i = 0; i < 2 * N; i++)
    {
        if(pre[A[i % N]] == 0)pre[A[i % N]] = i + 1;
        else
        {
            int idx = (pre[A[i % N]] - 1) % N;
            nxt[0][idx] = (i + 1) % N;
            over[0][idx] = (nxt[0][idx] <= idx % N || idx == i % N) ? 1 : 0;
            pre[A[i % N]] = i + 1;
        }
    }

    for(int i = 1; i < 60; i++)
    {
        for(int j = 0; j < N; j++)
        {
            nxt[i][j] = nxt[i - 1][nxt[i - 1][j]];
            over[i][j] = min(10000000000000, over[i - 1][j] + over[i - 1][nxt[i - 1][j]]);
        }
    }

    ll mem = 0, sum = 0;
    for(int i = 59; i >= 0; i--)
    {
        if(sum + over[i][mem] < K)
        {
            sum += over[i][mem];
            mem = nxt[i][mem];
        }
    }
    /*
    ll l = 0, r = 100000000000000001;
    while(1)
    {
        ll mid = (l + r) / 2;
        ll now = 0, cnt = 0;
        for(int j = 0; j < 60; j++)if(mid & (1LL << j))
        {
            cnt += over[j][now];
            now = nxt[j][now];
        }
        if(K - 1 == cnt)
        {
            mem = now;
            break;
        }
        if(cnt < K - 1)l = mid;
        else r = mid;
    }
    */

    int bit[200010] = {0};
    vector<int> ans;
    for(int i = mem; i < N; i++)
    {
        if(bit[A[i]])
        {
            while(ans.back() != A[i])
            {
                bit[ans.back()] ^= 1;
                ans.pop_back();
            }
            bit[ans.back()] ^= 1;
            ans.pop_back();
        }
        else
        {
            bit[A[i]] ^= 1;
            ans.push_back(A[i]);
        }
    }

    for(int i = 0; i < ans.size(); i++)
    {
        cout << ans[i];
        if(i != ans.size())cout << " ";
    }
    cout << endl;

    return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:40:29: error: no matching function for call to 'min(long int, ll)'
   40 |             over[i][j] = min(10000000000000, over[i - 1][j] + over[i - 1][nxt[i - 1][j]]);
      |                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:40:29: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'll' {aka 'long long int'})
   40 |             over[i][j] = min(10000000000000, over[i - 1][j] + over[i - 1][nxt[i - 1][j]]);
      |                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:40:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   40 |             over[i][j] = min(10000000000000, over[i - 1][j] + over[i - 1][nxt[i - 1][j]]);
      |                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~