Language: C++

#include<iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);(i)<(int)(n);(i)++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;(i)>=(int)(m);(i)--)
#define REP(i,n) rep(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;


template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

struct Edge {
	int to, cap, rev;
	Edge(int _to, int _cap, int _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, int from, int to, int cap, bool revFlag, int revCap) {
	G[from].push_back(Edge(to, cap, G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, G[from].size() - 1));
}



void solve() {
	ll n, k;
	cin >> n >> k;
    
	Array a(n);
	REP(i, n) cin >> a[i];

	Array next(n,n+1);//添字iが消えた後の位置
	Array first(202020, n);
	Array pre(202020, n);
	REP(i, n) {
		if (first[a[i]] == n) {
			first[a[i]] = i;
			pre[a[i]] = i;
			continue;
		}

		next[pre[a[i]]] = i - pre[a[i]] + 1;
		next[i] = n + first[a[i]] - i + 1;
		pre[a[i]] = i;
	}

	Matrix t(45,Array(n,-1));//2^i周期進んだ時の位置
	REP(i, n) {
		if (t[0][i] != -1) continue;
		ll now = i;
		Array p;
		p.push_back(now);
		while (now < n) {
			now += next[now];
			if (now < n) {
				if (t[0][now] != -1) {
					now = t[0][now];
					break;
				}
				p.push_back(now);
			}
		}
		for(auto j:p) t[0][j] = now % n;//1周期進んだ位置
	}

	REP(i, 44) {
		REP(j, n) {
			t[i + 1][j] = t[i][t[i][j]];//ダブリング
		}
	}

	ll pos = 0;
	REP(i, 45) {
		if ((k - 1LL) & (1LL << (LL)i)) {
			pos = t[i][pos];
		}
	}

	while (pos != n) {
		while (pos < n && pos + next[pos] <= n) {
			pos += next[pos];
		}
		if (pos < n) {
			cout << a[pos] << " ";
			pos++;
		}
	}
	cout << en;
}

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

	solve();
	//int t; cin >> t; REP(i, t) solve();

	return 0;
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:117:42: error: 'LL' was not declared in this scope; did you mean 'll'?
  117 |                 if ((k - 1LL) & (1LL << (LL)i)) {
      |                                          ^~
      |                                          ll
a.cc:117:45: error: expected ')' before 'i'
  117 |                 if ((k - 1LL) & (1LL << (LL)i)) {
      |                                 ~           ^
      |                                             )
a.cc:119:18: error: expected ')' before '}' token
  119 |                 }
      |                  ^
      |                  )
  120 |         }
      |         ~         
a.cc:117:20: note: to match this '('
  117 |                 if ((k - 1LL) & (1LL << (LL)i)) {
      |                    ^
a.cc:120:9: error: expected primary-expression before '}' token
  120 |         }
      |         ^