結果

問題 No.1725 [Cherry 3rd Tune D] 無言の言葉
ユーザー stoqstoq
提出日時 2021-07-01 06:08:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 73 ms / 4,000 ms
コード長 2,175 bytes
コンパイル時間 8,144 ms
コンパイル使用メモリ 310,516 KB
実行使用メモリ 44,560 KB
最終ジャッジ日時 2023-08-24 00:58:04
合計ジャッジ時間 11,645 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,816 KB
testcase_01 AC 3 ms
7,708 KB
testcase_02 AC 2 ms
7,708 KB
testcase_03 AC 3 ms
7,716 KB
testcase_04 AC 2 ms
7,728 KB
testcase_05 AC 2 ms
7,692 KB
testcase_06 AC 5 ms
7,708 KB
testcase_07 AC 3 ms
7,680 KB
testcase_08 AC 4 ms
7,820 KB
testcase_09 AC 2 ms
7,668 KB
testcase_10 AC 3 ms
7,780 KB
testcase_11 AC 2 ms
7,668 KB
testcase_12 AC 6 ms
8,712 KB
testcase_13 AC 5 ms
8,144 KB
testcase_14 AC 23 ms
8,420 KB
testcase_15 AC 6 ms
8,540 KB
testcase_16 AC 7 ms
8,852 KB
testcase_17 AC 13 ms
11,652 KB
testcase_18 AC 29 ms
9,068 KB
testcase_19 AC 10 ms
9,048 KB
testcase_20 AC 4 ms
7,932 KB
testcase_21 AC 25 ms
7,848 KB
testcase_22 AC 40 ms
19,976 KB
testcase_23 AC 39 ms
17,292 KB
testcase_24 AC 28 ms
15,812 KB
testcase_25 AC 51 ms
26,060 KB
testcase_26 AC 42 ms
22,756 KB
testcase_27 AC 45 ms
29,112 KB
testcase_28 AC 57 ms
28,188 KB
testcase_29 AC 54 ms
28,224 KB
testcase_30 AC 55 ms
32,912 KB
testcase_31 AC 37 ms
20,192 KB
testcase_32 AC 73 ms
41,100 KB
testcase_33 AC 73 ms
43,664 KB
testcase_34 AC 68 ms
39,120 KB
testcase_35 AC 65 ms
35,156 KB
testcase_36 AC 69 ms
39,664 KB
testcase_37 AC 45 ms
7,680 KB
testcase_38 AC 45 ms
7,656 KB
testcase_39 AC 46 ms
7,672 KB
testcase_40 AC 46 ms
7,668 KB
testcase_41 AC 45 ms
7,728 KB
testcase_42 AC 2 ms
7,668 KB
testcase_43 AC 34 ms
44,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include "testlib.h"
using namespace std;
using ll = long long;
#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")

void validator1(string &X, string &Y, int &Q)
{
  X = inf.readString("[a-z]{1,100000}");
  Y = inf.readString("[a-z]{1,100000}");
  Q = inf.readInt(1, 50000);
  inf.readEoln();
}

void validator2(int &l, int &r, char &c)
{
  const int MAX = int(1e9);
  l = inf.readInt(1, MAX);
  inf.readSpace();
  r = inf.readInt(1, MAX);
  inf.readSpace();
  c = inf.readChar();
  inf.readEoln();
  assert(l <= r);
  assert(islower(c));
}

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

// F_k の [0, r) に含まれる c の個数
ll 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(int argc, char *argv[])
{
  registerValidation(argc, argv);
  string X, Y;
  int Q;
  validator1(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, 40)
  {
    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;
    validator2(l, r, c);
    cout << f(k, r, c - 'a') - f(k, l - 1, c - 'a') << "\n";
  }
  inf.readEof();
}
0