// 提出時にassertはオフ #ifndef DEBUG #ifndef NDEBUG #define NDEBUG #endif #endif #include using namespace std; using ll = long long; #define all(x) (x).begin(), (x).end() template using vec = vector; struct rolhash_mod { public: // [2, MOD - 2]のbaseを乱数として生成 static ll genBase() { random_device seed; // 非決定的な乱数 mt19937_64 mt(seed()); // メルセンヌ・ツイスタ 64bit uniform_int_distribution randbase(2LL, MOD - 2); return randbase(mt); } // べき乗のmod(tableを用意せずその場でやってるのでlog(beki)かかる) constexpr static ll power(ll base, ll beki) { rolhash_mod curbekiMod(base); rolhash_mod ret(1); while(beki > 0) { if(beki & 1) ret *= curbekiMod; curbekiMod *= curbekiMod; beki >>= 1; } return ret.val(); } constexpr rolhash_mod(ll x = 0) : value(calcMod(x)) {} constexpr ll val() const { return value; } constexpr rolhash_mod &operator+=(const rolhash_mod &a) { if((value += a.value) >= MOD) value -= MOD; return *this; } constexpr rolhash_mod &operator-=(const rolhash_mod &a) { *this += (MOD - a.value); return *this; } constexpr rolhash_mod &operator*=(const rolhash_mod &a) { __int128_t product = (__int128_t)value * a.value; product = (product >> 61) + (product & MOD); if(product >= MOD) product -= MOD; value = product; return *this; } constexpr rolhash_mod operator+(const rolhash_mod &a) const { rolhash_mod cpy(*this); return cpy += a; } constexpr rolhash_mod operator-(const rolhash_mod &a) const { rolhash_mod cpy(*this); return cpy -= a; } constexpr rolhash_mod operator*(const rolhash_mod &a) const { rolhash_mod cpy(*this); return cpy *= a; } constexpr bool operator==(const rolhash_mod &a) { return value == a.value; } private: ll value; // 中で保持しておくmod constexpr static ll MOD = (1LL << 61) - 1; constexpr static ll calcMod(const ll &x) { ll cur = x >> 61; if((cur += (x & MOD)) >= MOD) cur -= MOD; return cur; } }; // 部分文字列[l,r)のhash値を返すqueryを定数時間で struct rolhash { public: template rolhash(const vector &input) : base(rolhash_mod::genBase()), N(input.size()) { basebeki_table = vector(N + 1); basebeki_table[0] = 1; for(int i = 1; i <= N; ++i) { basebeki_table[i] = basebeki_table[i - 1] * base; } front_table = vector(N + 1); for(int i = 1; i <= N; ++i) { front_table[i] = front_table[i - 1] * base + input[i - 1]; } } // 部分列[l,r)のhash値を返す rolhash_mod query(int l, int r) const { return (front_table[r] - front_table[l] * basebeki_table[r - l]); } // 部分列[0,i)のhash値を返す rolhash_mod get_basebeki(int beki) const { return basebeki_table[beki]; } // baseのbeki乗を返す rolhash_mod get_front(int i) const { return front_table[i]; } private: constexpr static ll MOD = (1LL << 61) - 1; const ll base; const int N; // baseの0乗からN乗を記録 vector basebeki_table; // [0,i)の部分列のhash値を記録 vector front_table; }; int N, K; vec A; // X_iの最初j数字のhash値を返す rolhash_mod calc_hash(int i, int j, const rolhash &rol) { if(j <= i) return rol.get_front(j); // [0,j) // [0,i) + [i+1,j) return rol.get_front(i) * rol.get_basebeki(j - i) + rol.query(i + 1, j); } // X_iとX_jの大小比較 bool cmphash(int i, int j, const rolhash &rol) { if(calc_hash(i, N - 1, rol) == calc_hash(j, N - 1, rol)) return false; int l = 0, r = N - 1; while(r - l > 1) { int m = (l + r) / 2; if(calc_hash(i, m, rol) == calc_hash(j, m, rol)) l = m; else r = m; } int X_i_num = A[l], X_j_num = A[l]; if(i < l) X_i_num = A[l + 1]; if(j < l) X_j_num = A[l + 1]; return X_i_num < X_j_num; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> N >> K; A = vec(N); for(int &a : A) cin >> a; rolhash rol(A); vec perm(N); for(int i = 0; i < N; i++) perm[i] = i; sort(all(perm), [&rol](int i, int j) -> bool{ return cmphash(i, j, rol); }); int ansIndex = perm[K - 1]; for(int i = 0; i < N; i++){ if(i != ansIndex) cout << A[i] << " "; } cout << "\n"; }