結果

問題 No.2554 MMA文字列2 (Query Version)
ユーザー KudeKude
提出日時 2023-11-25 14:32:04
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 770 ms / 5,000 ms
コード長 1,780 bytes
コンパイル時間 4,224 ms
コンパイル使用メモリ 279,364 KB
実行使用メモリ 165,560 KB
最終ジャッジ日時 2023-11-25 14:32:36
合計ジャッジ時間 24,223 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 3 ms
6,676 KB
testcase_04 AC 5 ms
6,676 KB
testcase_05 AC 5 ms
6,676 KB
testcase_06 AC 5 ms
6,676 KB
testcase_07 AC 3 ms
6,676 KB
testcase_08 AC 5 ms
6,676 KB
testcase_09 AC 5 ms
6,676 KB
testcase_10 AC 5 ms
6,676 KB
testcase_11 AC 3 ms
6,676 KB
testcase_12 AC 38 ms
44,024 KB
testcase_13 AC 390 ms
164,868 KB
testcase_14 AC 86 ms
43,636 KB
testcase_15 AC 296 ms
165,424 KB
testcase_16 AC 241 ms
43,896 KB
testcase_17 AC 337 ms
84,420 KB
testcase_18 AC 78 ms
8,448 KB
testcase_19 AC 164 ms
43,896 KB
testcase_20 AC 365 ms
165,132 KB
testcase_21 AC 123 ms
13,540 KB
testcase_22 AC 472 ms
165,560 KB
testcase_23 AC 433 ms
165,560 KB
testcase_24 AC 462 ms
165,560 KB
testcase_25 AC 446 ms
165,560 KB
testcase_26 AC 449 ms
165,560 KB
testcase_27 AC 534 ms
165,560 KB
testcase_28 AC 437 ms
165,560 KB
testcase_29 AC 487 ms
165,560 KB
testcase_30 AC 452 ms
165,560 KB
testcase_31 AC 449 ms
165,560 KB
testcase_32 AC 27 ms
6,676 KB
testcase_33 AC 26 ms
6,676 KB
testcase_34 AC 28 ms
6,676 KB
testcase_35 AC 29 ms
6,676 KB
testcase_36 AC 54 ms
6,676 KB
testcase_37 AC 733 ms
165,560 KB
testcase_38 AC 770 ms
165,560 KB
testcase_39 AC 726 ms
165,560 KB
testcase_40 AC 748 ms
165,560 KB
testcase_41 AC 764 ms
165,560 KB
testcase_42 AC 679 ms
165,560 KB
testcase_43 AC 711 ms
165,560 KB
testcase_44 AC 675 ms
165,560 KB
testcase_45 AC 694 ms
165,560 KB
testcase_46 AC 668 ms
165,560 KB
testcase_47 AC 245 ms
165,560 KB
testcase_48 AC 214 ms
165,560 KB
testcase_49 AC 213 ms
165,560 KB
testcase_50 AC 214 ms
165,560 KB
testcase_51 AC 211 ms
165,560 KB
testcase_52 AC 167 ms
165,560 KB
testcase_53 AC 200 ms
165,560 KB
testcase_54 AC 175 ms
165,560 KB
testcase_55 AC 173 ms
165,560 KB
testcase_56 AC 170 ms
165,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

struct S {
  ll v01, v02, v03, v12, v13, v23;
};

S op(const S& x, const S& y) {
  return S{
    x.v01 + y.v01,
    x.v02 + x.v01 * y.v12 + y.v02,
    x.v03 + x.v02 * y.v23 + x.v01 * y.v13 + y.v03,
    x.v12 + y.v12,
    x.v13 + x.v12 * y.v23 + y.v13,
    x.v23 + y.v23
  };
}
S e() {
  return S{0, 0, 0, 0, 0, 0};
}

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s;
  cin >> n >> s;
  S match{1, 0, 0, 1, 0, 0}, unmatch{0, 0, 0, 0, 0, 1};
  vector<segtree<S, op, e>> seg;
  rep(c, 26) {
    vector<S> init(n);
    rep(i, n) {
      init[i] = s[i] - 'A' == c ? match : unmatch;
    }
    seg.emplace_back(init);
  }
  int q;
  cin >> q;
  while (q--) {
    int op;
    cin >> op;
    if (op == 1) {
      int x;
      char c;
      cin >> x >> c;
      x--;
      seg[s[x] - 'A'].set(x, unmatch);
      s[x] = c;
      seg[s[x] - 'A'].set(x, match);
    } else {
      int l, r;
      cin >> l >> r;
      l--;
      ll ans = 0;
      rep(c, 26) ans += seg[c].prod(l, r).v03;
      cout << ans << '\n';
    }
  }
}
0