結果

問題 No.2210 equence Squence Seuence
ユーザー CoCo_Japan_panCoCo_Japan_pan
提出日時 2023-02-11 18:33:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,739 bytes
コンパイル時間 2,455 ms
コンパイル使用メモリ 207,756 KB
実行使用メモリ 7,928 KB
最終ジャッジ日時 2023-09-22 14:22:33
合計ジャッジ時間 20,268 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 431 ms
4,828 KB
testcase_07 AC 1,496 ms
6,700 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 WA -
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1,859 ms
7,816 KB
testcase_14 WA -
testcase_15 AC 1,536 ms
7,820 KB
testcase_16 AC 1,775 ms
7,796 KB
testcase_17 WA -
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 WA -
testcase_21 AC 1 ms
4,380 KB
testcase_22 WA -
testcase_23 AC 1,003 ms
7,032 KB
testcase_24 AC 680 ms
5,944 KB
testcase_25 AC 880 ms
6,512 KB
testcase_26 AC 1,196 ms
7,668 KB
testcase_27 AC 260 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 提出時にassertはオフ
#ifndef DEBUG
#ifndef NDEBUG
#define NDEBUG
#endif
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define all(x) (x).begin(), (x).end()
template <class T>
using vec = vector<T>;

struct rolhash_mod {
   public:
    // [2, MOD - 2]のbaseを乱数として生成
    static ll genBase() {
        random_device seed;     // 非決定的な乱数
        mt19937_64 mt(seed());  // メルセンヌ・ツイスタ 64bit
        uniform_int_distribution<ll> 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 <class T>
    rolhash(const vector<T> &input) : base(rolhash_mod::genBase()), N(input.size()) {
        basebeki_table = vector<rolhash_mod>(N + 1);
        basebeki_table[0] = 1;
        for(int i = 1; i <= N; ++i) {
            basebeki_table[i] = basebeki_table[i - 1] * base;
        }
        front_table = vector<rolhash_mod>(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<rolhash_mod> basebeki_table;
    // [0,i)の部分列のhash値を記録
    vector<rolhash_mod> front_table;
};

int N, K;
vec<int> 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<int>(N);
    for(int &a : A) cin >> a;
    rolhash rol(A);
    vec<int> 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";
}
0