結果

問題 No.1725 [Cherry 3rd Tune D] 無言の言葉
ユーザー stoqstoq
提出日時 2021-07-01 05:57:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 4,000 ms
コード長 1,682 bytes
コンパイル時間 2,896 ms
コンパイル使用メモリ 204,332 KB
実行使用メモリ 23,768 KB
最終ジャッジ日時 2023-07-29 06:21:26
合計ジャッジ時間 8,348 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,596 KB
testcase_01 AC 2 ms
5,360 KB
testcase_02 AC 2 ms
5,436 KB
testcase_03 AC 3 ms
5,352 KB
testcase_04 AC 2 ms
5,428 KB
testcase_05 AC 2 ms
5,356 KB
testcase_06 AC 4 ms
5,488 KB
testcase_07 AC 3 ms
5,416 KB
testcase_08 AC 4 ms
5,488 KB
testcase_09 AC 2 ms
5,344 KB
testcase_10 AC 3 ms
5,496 KB
testcase_11 AC 2 ms
5,440 KB
testcase_12 AC 5 ms
6,384 KB
testcase_13 AC 5 ms
6,500 KB
testcase_14 AC 19 ms
6,476 KB
testcase_15 AC 6 ms
6,712 KB
testcase_16 AC 6 ms
6,956 KB
testcase_17 AC 10 ms
7,016 KB
testcase_18 AC 22 ms
6,248 KB
testcase_19 AC 8 ms
6,056 KB
testcase_20 AC 4 ms
5,732 KB
testcase_21 AC 21 ms
6,028 KB
testcase_22 AC 32 ms
11,996 KB
testcase_23 AC 32 ms
11,164 KB
testcase_24 AC 22 ms
9,520 KB
testcase_25 AC 41 ms
15,608 KB
testcase_26 AC 33 ms
13,400 KB
testcase_27 AC 34 ms
17,080 KB
testcase_28 AC 46 ms
16,360 KB
testcase_29 AC 44 ms
15,812 KB
testcase_30 AC 41 ms
18,268 KB
testcase_31 AC 25 ms
11,232 KB
testcase_32 AC 54 ms
22,680 KB
testcase_33 AC 54 ms
22,104 KB
testcase_34 AC 51 ms
21,228 KB
testcase_35 AC 50 ms
20,152 KB
testcase_36 AC 52 ms
21,944 KB
testcase_37 AC 37 ms
5,344 KB
testcase_38 AC 37 ms
5,608 KB
testcase_39 AC 37 ms
5,412 KB
testcase_40 AC 37 ms
5,368 KB
testcase_41 AC 37 ms
5,372 KB
testcase_42 AC 2 ms
5,336 KB
testcase_43 AC 24 ms
23,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); i++)
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

int n, m;                             // X, Y の長さ
int len[32];                          // F_k の長さ
int F_all[32][26];                    // F_k 全体に含まれる c の個数
int X_L[100010][26], Y_L[100010][26]; // X, Y の先頭 i 文字に含まれる c の個数

// F_k の [0, r) に含まれる c の個数
int f(int k, int r, int c)
{
  if (k == 0)
    return X_L[r][c];
  assert(r <= len[k]);
  // F_k = F_{k-1} + Y + rev(F_{k-1})
  if (r <= len[k - 1])
    return f(k - 1, r, c);
  else if (r <= len[k - 1] + m)
    return F_all[k - 1][c] + Y_L[r - len[k - 1]][c];
  else
    return F_all[k - 1][c] + Y_L[m][c] + F_all[k - 1][c] - f(k - 1, len[k] - r, c);
}

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

  string X, Y;
  int Q;
  cin >> X >> Y >> Q;
  n = X.length(), m = Y.length();
  rep(j, 26) X_L[0][j] = Y_L[0][j] = 0;
  rep(i, n) rep(j, 26)
  {
    X_L[i + 1][j] += X_L[i][j] + (X[i] == j + 'a');
  }
  rep(i, m) rep(j, 26)
  {
    Y_L[i + 1][j] += Y_L[i][j] + (Y[i] == j + 'a');
  }

  int k = -1;
  rep(i, 32)
  {
    if (i == 0)
    {
      len[i] = n;
      rep(j, 26) F_all[0][j] = X_L[n][j];
    }
    else
    {
      len[i] = len[i - 1] * 2 + m;
      rep(j, 26) F_all[i][j] = F_all[i - 1][j] * 2 + Y_L[m][j];
    }
    if (len[i] >= 1000000010)
    {
      k = i;
      break;
    }
  }
  assert(k != -1);

  rep(i, Q)
  {
    int l, r;
    char c;
    cin >> l >> r >> c;
    cout << f(k, r, c - 'a') - f(k, l - 1, c - 'a') << "\n";
  }
}
0