結果

問題 No.1725 [Cherry 3rd Tune D] 無言の言葉
ユーザー tnakao0123tnakao0123
提出日時 2021-10-30 17:21:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 56 ms / 4,000 ms
コード長 1,813 bytes
コンパイル時間 438 ms
コンパイル使用メモリ 45,364 KB
実行使用メモリ 24,320 KB
最終ジャッジ日時 2024-04-16 16:24:57
合計ジャッジ時間 3,461 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
24,064 KB
testcase_01 AC 17 ms
24,064 KB
testcase_02 AC 17 ms
24,064 KB
testcase_03 AC 17 ms
24,192 KB
testcase_04 AC 16 ms
24,064 KB
testcase_05 AC 17 ms
24,064 KB
testcase_06 AC 19 ms
24,192 KB
testcase_07 AC 17 ms
24,064 KB
testcase_08 AC 18 ms
24,064 KB
testcase_09 AC 17 ms
24,192 KB
testcase_10 AC 17 ms
24,064 KB
testcase_11 AC 17 ms
24,192 KB
testcase_12 AC 19 ms
24,192 KB
testcase_13 AC 19 ms
24,192 KB
testcase_14 AC 36 ms
24,064 KB
testcase_15 AC 19 ms
24,192 KB
testcase_16 AC 20 ms
24,064 KB
testcase_17 AC 24 ms
24,064 KB
testcase_18 AC 41 ms
24,192 KB
testcase_19 AC 23 ms
24,192 KB
testcase_20 AC 19 ms
24,064 KB
testcase_21 AC 38 ms
24,064 KB
testcase_22 AC 44 ms
24,064 KB
testcase_23 AC 44 ms
24,192 KB
testcase_24 AC 35 ms
24,064 KB
testcase_25 AC 49 ms
24,320 KB
testcase_26 AC 41 ms
24,192 KB
testcase_27 AC 40 ms
24,192 KB
testcase_28 AC 53 ms
24,192 KB
testcase_29 AC 52 ms
24,320 KB
testcase_30 AC 48 ms
24,192 KB
testcase_31 AC 38 ms
24,064 KB
testcase_32 AC 56 ms
24,192 KB
testcase_33 AC 55 ms
24,192 KB
testcase_34 AC 55 ms
24,192 KB
testcase_35 AC 54 ms
24,192 KB
testcase_36 AC 54 ms
24,320 KB
testcase_37 AC 54 ms
24,064 KB
testcase_38 AC 54 ms
24,192 KB
testcase_39 AC 55 ms
24,192 KB
testcase_40 AC 54 ms
24,064 KB
testcase_41 AC 54 ms
24,192 KB
testcase_42 AC 17 ms
24,064 KB
testcase_43 AC 20 ms
24,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1725.cc:  No.1725 [Cherry 3rd Tune D] 無言の言葉 - yukicoder
 */

#include<cstdio>
#include<cstring>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_K = 30;
const int MAX_R = 1000000000;

/* typedef */

struct Vec {
  int vs[26];
  Vec(): vs() {}
  int &operator[](int i) { return vs[i]; }

  Vec operator+(const Vec &e) const {
    Vec r;
    for (int i = 0; i < 26; i++) r.vs[i] = vs[i] + e.vs[i];
    return r;
  }

  Vec operator-(const Vec &e) const {
    Vec r;
    for (int i = 0; i < 26; i++) r.vs[i] = vs[i] - e.vs[i];
    return r;
  }
};

/* global variables */

char sx[MAX_N + 4], sy[MAX_N + 4];
Vec xvs[MAX_N + 1], yvs[MAX_N + 1], fvs[MAX_K];
int xn, yn, fns[MAX_K];

/* subroutines */

void s2vecs(int n, char s[], Vec vs[]) {
  for (int i = 0; i < n; i++) {
    vs[i + 1] = vs[i];
    vs[i + 1][s[i] - 'a']++;
  }
}

int rec(int k, int r, int ci) {
  if (k <= 0) return xvs[min(xn, r)][ci];
  k--;

  if (r <= fns[k])
    return rec(k, r, ci);

  if (r <= fns[k] + yn)
    return fvs[k][ci] + yvs[r - fns[k]][ci];

  r -= fns[k] + yn;
  return fvs[k + 1][ci] - rec(k, max(0, fns[k] - r), ci);
}

/* main */

int main() {
  int qn;
  scanf("%s%s%d", sx, sy, &qn);
  xn = strlen(sx), yn = strlen(sy);

  s2vecs(xn, sx, xvs);
  s2vecs(yn, sy, yvs);

  fns[0] = xn;
  fvs[0] = xvs[xn];
  int k = 0;
  while (fns[k] < MAX_R) {
    fns[k + 1] = fns[k] * 2 + yn;
    fvs[k + 1] = fvs[k] + yvs[yn] + fvs[k];
    k++;
  }
  //printf("k=%d ", k);
  //for (int i = 0; i <= k; i++) printf("%d ", fns[i]); putchar('\n');

  while (qn--) {
    int l, r;
    char sc[4];
    scanf("%d%d%s", &l, &r, sc);
    l--;
    int ci = sc[0] - 'a';

    int d = rec(k, r, ci) - rec(k, l, ci);
    printf("%d\n", d);
  }
  return 0;
}
0