結果

問題 No.958 たぷりすたべる (回文)
ユーザー risujirohrisujiroh
提出日時 2019-12-21 00:33:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,558 bytes
コンパイル時間 2,430 ms
コンパイル使用メモリ 174,156 KB
実行使用メモリ 7,744 KB
最終ジャッジ日時 2023-09-25 06:14:31
合計ジャッジ時間 19,248 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 6 ms
4,380 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 WA -
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 4 ms
4,380 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 1,558 ms
4,376 KB
testcase_28 AC 996 ms
4,376 KB
testcase_29 AC 1,061 ms
4,376 KB
testcase_30 AC 1,107 ms
4,376 KB
testcase_31 AC 1,061 ms
4,376 KB
testcase_32 AC 995 ms
4,380 KB
testcase_33 AC 997 ms
4,376 KB
testcase_34 AC 1,060 ms
4,376 KB
testcase_35 AC 1,054 ms
4,376 KB
testcase_36 AC 1,043 ms
4,376 KB
testcase_37 TLE -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

struct RollingHash {
  static constexpr long long m31 = (1LL << 31) - 1;
  static int mod_m31(long long a) {
    a = (a >> 31) + (a & m31);
    return a >= m31 ? a - m31 : a;
  }
  static long long base[2];
  static vector<int> powb[2];
  vector<int> h[2];
  RollingHash(const string& s) : h{{0}, {0}} {
    for (int k : {0, 1}) {
      for (char c : s) h[k].push_back(mod_m31(h[k].back() * base[k] + c));
      while (powb[k].size() <= s.size())
        powb[k].push_back(mod_m31(powb[k].back() * base[k]));
    }
  }
  int get(int l, int r, int k) const {
    return mod_m31(h[k][r] + (m31 - h[k][l]) * powb[k][r - l]);
  }
  auto get(int l, int r) const { return make_pair(get(l, r, 0), get(l, r, 1)); }
  static long long powerb(long long n, int k) {
    long long res = 1, t = base[k];
    while (n) {
      if (n & 1) {
        res = mod_m31(res * t);
      }
      t = mod_m31(t * t);
      n >>= 1;
    }
    return res;
  }
  static int merge(long long hl, long long hr, long long len, int k) {
    return mod_m31(hl * powerb(len, k) + hr);
  }
  static auto merge(pair<int, int> hl, pair<int, int> hr, long long len) {
    return make_pair(merge(hl.first, hr.first, len, 0), merge(hl.second, hr.second, len, 1));
  }
};
long long RollingHash::base[2] = {1095803926, 1410736294};
vector<int> RollingHash::powb[2] = {{1}, {1}};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long long n, k, q;
  cin >> n >> k >> q;
  string s;
  cin >> s;
  RollingHash rh(s + s);
  reverse(begin(s), end(s));
  RollingHash rev(s + s);
  auto pw = [&](auto h, long long num) {
    auto res = make_pair(0, 0);
    long long len = n;
    while (num) {
      if (num & 1) {
        res = rh.merge(res, h, len);
      }
      h = rh.merge(h, h, len);
      len *= 2;
      num >>= 1;
    }
    return res;
  };
  while (q--) {
    long long a;
    cin >> a;
    --a;
    auto f = [&](const auto& rh, long long l, long long r) {
      if (r - l <= n) {
        return rh.get(l % n, l % n + (r - l));
      }
      auto x = rh.get(l % n, n);
      l = (l + n - 1) / n * n;
      auto z = rh.get(0, r % n);
      int zl = r % n;
      r = r / n * n;
      auto y = pw(rh.get(0, n), (r - l) / n);
      return rh.merge(rh.merge(x, y, r - l), z, zl);
    };
    long long ok = 1, ng = min(a + 1, k * n - a) + 1;
    while (ng - ok > 1) {
      long long mid = (ok + ng) / 2;
      (f(rh, a, a + mid) == f(rev, k * n - a - 1, k * n - a - 1 + mid) ? ok : ng) = mid;
    }
    cout << 2 * ok - 1 << '\n';
  }
}
0