結果

問題 No.1725 [Cherry 3rd Tune D] 無言の言葉
ユーザー stoqstoq
提出日時 2021-07-01 05:57:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 56 ms / 4,000 ms
コード長 1,682 bytes
コンパイル時間 2,567 ms
コンパイル使用メモリ 200,008 KB
実行使用メモリ 23,936 KB
最終ジャッジ日時 2024-04-16 13:28:28
合計ジャッジ時間 5,944 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 5 ms
5,376 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 19 ms
5,376 KB
testcase_15 AC 5 ms
5,376 KB
testcase_16 AC 6 ms
5,376 KB
testcase_17 AC 9 ms
5,376 KB
testcase_18 AC 21 ms
5,376 KB
testcase_19 AC 8 ms
5,376 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 20 ms
5,376 KB
testcase_22 AC 35 ms
10,240 KB
testcase_23 AC 33 ms
9,472 KB
testcase_24 AC 24 ms
7,680 KB
testcase_25 AC 39 ms
13,952 KB
testcase_26 AC 34 ms
11,648 KB
testcase_27 AC 35 ms
15,104 KB
testcase_28 AC 42 ms
14,720 KB
testcase_29 AC 44 ms
14,208 KB
testcase_30 AC 42 ms
16,512 KB
testcase_31 AC 26 ms
9,216 KB
testcase_32 AC 56 ms
21,148 KB
testcase_33 AC 55 ms
21,876 KB
testcase_34 AC 54 ms
20,480 KB
testcase_35 AC 53 ms
18,560 KB
testcase_36 AC 52 ms
20,096 KB
testcase_37 AC 37 ms
5,376 KB
testcase_38 AC 37 ms
5,376 KB
testcase_39 AC 37 ms
5,376 KB
testcase_40 AC 37 ms
5,376 KB
testcase_41 AC 37 ms
5,376 KB
testcase_42 AC 3 ms
5,376 KB
testcase_43 AC 25 ms
23,936 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