// Library Codes are in: https://github.com/reinsirk/sirkit-cpp-library // GCC バグ対策 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128217 #pragma GCC optimize("no-tree-loop-vectorize") #include #include using namespace std; using namespace atcoder; #define SKIP_RUNTIME_CHECKS constexpr int64_t INF = static_cast(1) << 60; namespace sirkit { #ifndef SIRKIT_INF_DEFINED #define SIRKIT_INF_DEFINED inline constexpr std::int64_t kInf = std::int64_t{1} << 60; #endif #ifndef SIRKIT_UNWEIGHTED_GRAPH_DEFINED #define SIRKIT_UNWEIGHTED_GRAPH_DEFINED using Graph = std::vector>; #endif #ifndef SIRKIT_GRAPH_TYPES_DEFINED #define SIRKIT_GRAPH_TYPES_DEFINED struct Edge { int to; std::int64_t w; Edge(int destination, std::int64_t weight) : to(destination), w(weight) { } }; using WGraph = std::vector>; #endif #ifndef SIRKIT_CHMIN_DEFINED #define SIRKIT_CHMIN_DEFINED #define SIRKIT_TEMP_DEFINE_CHMIN template constexpr bool chmin(T &a, T b); #endif #ifndef SIRKIT_CHMAX_DEFINED #define SIRKIT_CHMAX_DEFINED #define SIRKIT_TEMP_DEFINE_CHMAX template constexpr bool chmax(T &a, T b); #endif #ifndef SIRKIT_POW64I_DEFINED #define SIRKIT_POW64I_DEFINED #define SIRKIT_TEMP_DEFINE_POW64I constexpr std::uint64_t pow64i(std::uint64_t x, std::uint64_t n); #endif #ifndef SIRKIT_IS_MUL_OVERFLOW_DEFINED #define SIRKIT_IS_MUL_OVERFLOW_DEFINED #define SIRKIT_TEMP_DEFINE_IS_MUL_OVERFLOW constexpr bool is_mul_overflow(std::int64_t a, std::int64_t b); #endif } // namespace sirkit using namespace sirkit; struct S { array, 4> v; }; S e() { S e; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { e.v.at(i).at(j) = 0; } } return e; } S op(S a, S b) { S ret = e(); for (int i = 0; i < 4; i++) { for (int j = i; j < 4; j++) { for (int u = j; u < 4; u++) { for (int k = u; k < 4; k++) { chmax(ret.v.at(i).at(k), a.v.at(i).at(j) + b.v.at(u).at(k)); } } } } return ret; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n, q; cin >> n >> q; string s; cin >> s; vector v(n); for (int i = 0; i < n; i++) { v.at(i) = e(); for (int j = 0; j < 4; j++) { for (int k = 0; k <= j; k++) { if (s.at(i) == 'A' + j) { v.at(i).v.at(k).at(j) = 1; } else { v.at(i).v.at(k).at(j) = 0; } } } } segtree sg(v); for (; q > 0; q--) { int t; cin >> t; if (t == 1) { int x; char c; cin >> x >> c; x--; v.at(x) = e(); s.at(x) = c; for (int j = 0; j < 4; j++) { for (int k = 0; k <= j; k++) { if (s.at(x) == 'A' + j) { v.at(x).v.at(k).at(j) = 1; } else { v.at(x).v.at(k).at(j) = 0; } } } sg.set(x, v.at(x)); } else { int l, r; cin >> l >> r; l--; auto x = sg.prod(l, r); int64_t ans = 0; for (auto &y : x.v) { for (auto z : y) { chmax(ans, z); } } cout << r - l - ans << endl; } } return 0; } namespace sirkit { #ifdef SIRKIT_TEMP_DEFINE_CHMIN #undef SIRKIT_TEMP_DEFINE_CHMIN template constexpr bool chmin(T &a, T b) { if (b < a) { a = b; return true; } return false; } #endif #ifdef SIRKIT_TEMP_DEFINE_CHMAX #undef SIRKIT_TEMP_DEFINE_CHMAX template constexpr bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } #endif #ifdef SIRKIT_TEMP_DEFINE_POW64I #undef SIRKIT_TEMP_DEFINE_POW64I constexpr std::uint64_t pow64i(std::uint64_t x, std::uint64_t n) { std::uint64_t result = 1; while (n != 0) { if ((n & 1) != 0) { result *= x; } n >>= 1; if (n != 0) { x *= x; } } return result; } #endif #ifdef SIRKIT_TEMP_DEFINE_IS_MUL_OVERFLOW #undef SIRKIT_TEMP_DEFINE_IS_MUL_OVERFLOW constexpr bool is_mul_overflow(std::int64_t a, std::int64_t b) { #if (defined(__GNUC__) || defined(__clang__)) && !defined(SIRKIT_FORCE_STANDARD_MUL_OVERFLOW) std::int64_t product; return __builtin_mul_overflow(a, b, &product); #else // 最小負数の絶対値も符号なし演算で安全に求める。 const std::uint64_t ua = a < 0 ? std::uint64_t{0} - static_cast(a) : static_cast(a); const std::uint64_t ub = b < 0 ? std::uint64_t{0} - static_cast(b) : static_cast(b); const std::uint64_t limit = (a < 0) != (b < 0) ? std::uint64_t{1} << 63 : static_cast(std::numeric_limits::max()); return ub != 0 && ua > limit / ub; #endif } #endif } // namespace sirkit