結果

問題 No.2210 equence Squence Seuence
ユーザー 👑 emthrmemthrm
提出日時 2023-02-10 21:37:48
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,128 ms / 2,000 ms
コード長 3,333 bytes
コンパイル時間 3,589 ms
コンパイル使用メモリ 259,040 KB
実行使用メモリ 9,596 KB
最終ジャッジ日時 2023-09-21 22:42:22
合計ジャッジ時間 14,390 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 149 ms
4,412 KB
testcase_04 AC 190 ms
4,592 KB
testcase_05 AC 286 ms
5,384 KB
testcase_06 AC 239 ms
5,136 KB
testcase_07 AC 721 ms
8,048 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1,128 ms
9,312 KB
testcase_14 AC 943 ms
9,596 KB
testcase_15 AC 878 ms
9,420 KB
testcase_16 AC 886 ms
9,348 KB
testcase_17 AC 945 ms
9,312 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 612 ms
7,964 KB
testcase_24 AC 429 ms
6,724 KB
testcase_25 AC 535 ms
7,516 KB
testcase_26 AC 748 ms
9,100 KB
testcase_27 AC 165 ms
4,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 998244353;
// constexpr int MOD = 1000000007;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

template <typename T = char>
struct RollingHash {
  const std::int64_t base;
  std::vector<T> str;

  template <typename U>
  explicit RollingHash(const U& str_, const std::int64_t base = generate_base())
      : base(base), hashes({0}), powers({1}) {
    const int n = str_.size();
    str.reserve(n);
    hashes.reserve(n + 1);
    powers.reserve(n + 1);
    for (const auto ch : str_) add(ch);
  }

  void add(const T ch) {
    assert(0 <= ch && ch < MOD);
    str.emplace_back(ch);
    const std::int64_t h = mul(hashes.back(), base) + ch;
    hashes.emplace_back(h >= MOD ? h - MOD : h);
    const std::int64_t p = mul(powers.back(), base);
    powers.emplace_back(p);
  }

  std::int64_t get(const int left, const int right) const {
    const std::int64_t res =
        hashes[right] - mul(hashes[left], powers[right - left]);
    return res < 0 ? res + MOD : res;
  }

 private:
  static constexpr int MOD_WIDTH = 61;
  static constexpr std::int64_t MOD = (INT64_C(1) << MOD_WIDTH) - 1;

  std::vector<std::int64_t> hashes, powers;

  static std::int64_t generate_base() {
    static std::mt19937_64 engine(std::random_device {} ());
    static std::uniform_int_distribution<std::int64_t> dist(0, MOD - 1);
    return dist(engine);
  }

  static std::int64_t mul(const std::int64_t a, const std::int64_t b) {
    const std::int64_t au = a >> 31, ad = a & ((UINT32_C(1) << 31) - 1);
    const std::int32_t bu = b >> 31, bd = b & ((UINT32_C(1) << 31) - 1);
    const std::int64_t mid = au * bd + ad * bu;
    std::int64_t res = au * bu * 2 + ad * bd + (mid >> 30)
                       + ((mid & ((UINT32_C(1) << 30) - 1)) << 31);
    res = (res >> MOD_WIDTH) + (res & MOD);
    return res >= MOD ? res - MOD : res;
  }
};

int main() {
  int n, k; cin >> n >> k;
  vector<int> a(n); REP(i, n) cin >> a[i];
  RollingHash<int> hash(a);
  vector<int> ans(n);
  iota(ALL(ans), 0);
  sort(ALL(ans), [&](const int l, const int r) -> bool {
    const int x = min(l, r);
    int lb = 0, ub = abs(r - l) + 1;
    while (ub - lb > 1) {
      const int mid = midpoint(lb, ub);
      (hash.get(x, x + mid) == hash.get(x + 1, x + 1 + mid) ? lb : ub) = mid;
    }
    if (lb == abs(r - l)) return false;
    return l < r ? a[l + 1 + lb] < a[l + lb] : a[r + lb] < a[r + 1 + lb];
  });
  // REP(i, n) cout << ans[i] << " \n"[i + 1 == n];
  vector<int> b = a;
  b.erase(next(b.begin(), ans[k - 1]));
  REP(i, n - 1) cout << b[i] << " \n"[i + 1 == n - 1];
  return 0;
}
0