結果

問題 No.1725 [Cherry 3rd Tune D] 無言の言葉
ユーザー chocono2230chocono2230
提出日時 2021-10-29 23:07:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,181 bytes
コンパイル時間 2,342 ms
コンパイル使用メモリ 204,668 KB
実行使用メモリ 86,172 KB
最終ジャッジ日時 2024-04-16 15:46:46
合計ジャッジ時間 12,581 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 RE -
testcase_05 RE -
testcase_06 WA -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;
const int INF = 1001001001;
string x, y;
int q;

ll rc(vector<ll> &sz, vector<ll> &alpsum, vector<ll> &alp, vector<ll> &rvalp, vector<ll> &syt, vector<ll> &syf, int lv, int r, bool mode, bool lst = false) {
  // if(q == 0) cerr << lv << " " << r << endl;
  // rep(i, alp.size()) cerr << alp.at(i) << " ";
  // cerr << endl;
  if(sz.at(lv) <= r) return alpsum.at(lv);
  if(lv == 0) {
    // cerr << lst << endl;
    if(!lst) return alp.at(r);
    else return rvalp.at(r);
  }
  ll bsz = sz.at(lv-1);
  bool nxmode = mode;
  if(mode) nxmode = true;
  if(r <= bsz) {
    return rc(sz, alpsum, alp, rvalp, syt, syf, lv-1, r, nxmode);
  }
  bsz += y.size();
  if(r <= bsz) {
    int d = r - sz.at(lv-1);
    ll res = 0;
    if(!mode) res = syt.at(d);
    else res = syf.at(d);
    return rc(sz, alpsum, alp, rvalp, syt, syf, lv-1, r, nxmode) + res;
  }
  ll res = rc(sz, alpsum, alp, rvalp, syt, syf, lv-1, r, nxmode) + syt.back();
  nxmode = true;
  return rc(sz, alpsum, alp, rvalp, syt, syf, lv-1, r - bsz, nxmode, true) + res;
}

ll fc(vector<ll> &sz, vector<ll> &alpsum, vector<ll> &alp, vector<ll> &rvalp, vector<ll> &syt, vector<ll> &syf, int r) {
  int lim = -1;
  rep(i, sz.size()) {
    if(r < sz.at(i)) {
      lim = i;
      break;
    }
  }
  if(lim == -1) exit(1);
  return rc(sz, alpsum, alp, rvalp, syt, syf, lim, r, false);
}

void init(vector<vector<ll>> &syt, vector<vector<ll>> &syf, string y) {
  auto ry = y;
  reverse(ALL(ry));
  rep(i, y.size()) {
    int now = y.at(i) - 'a';
    rep(j, 26) {
      syt.at(j).at(i+1) += syt.at(j).at(i);
      if(j == now) syt.at(j).at(i+1)++;
    }
    now = ry.at(i) - 'a';
    rep(j, 26) {
      syf.at(j).at(i+1) += syf.at(j).at(i);
      if(j == now) syf.at(j).at(i+1)++;
    }
  }
}

int main() {
  cin >> x >> y;
  vector<ll> sz(1, x.size());
  while(1) {
    ll p = sz.back();
    sz.push_back(p+p+y.size());
    if(sz.back() > INF) break;
  }
  vector syt(26, vector<ll>(y.size()+1, 0));
  vector syf(26, vector<ll>(y.size()+1, 0));
  init(syt, syf, y);
  vector sxt(26, vector<ll>(x.size()+1, 0));
  vector sxf(26, vector<ll>(x.size()+1, 0));
  init(sxt, sxf, x);
  vector alpsum(26, vector<ll>(sz.size(), 0));
  rep(i, 26) alpsum.at(i).at(0) = sxt.at(i).back();
  rep2(i, 1, alpsum.size()) {
    rep(j, 26) {
      alpsum.at(j).at(i) = alpsum.at(j).at(i-1) * 2 + syt.at(j).back();
    }
  }
  cin >> q;
  while(q--) {
    int l, r;
    char c;
    cin >> l >> r >> c;
    int idx = c - 'a';
    ll ans = fc(sz, alpsum.at(idx), sxt.at(idx), sxf.at(idx), syt.at(idx), syf.at(idx), r);
    if(l != 0) ans -= fc(sz, alpsum.at(idx), sxt.at(idx), sxf.at(idx), syt.at(idx), syf.at(idx), l-1);
    cout << ans << endl;
  }
  return 0;
}
0