結果

問題 No.2554 MMA文字列2 (Query Version)
ユーザー maeshunmaeshun
提出日時 2023-11-26 01:29:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,639 ms / 5,000 ms
コード長 1,971 bytes
コンパイル時間 4,798 ms
コンパイル使用メモリ 274,216 KB
実行使用メモリ 141,832 KB
最終ジャッジ日時 2023-11-26 01:30:44
合計ジャッジ時間 59,501 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 5 ms
6,676 KB
testcase_03 AC 6 ms
6,676 KB
testcase_04 AC 11 ms
6,676 KB
testcase_05 AC 11 ms
6,676 KB
testcase_06 AC 7 ms
6,676 KB
testcase_07 AC 6 ms
6,676 KB
testcase_08 AC 6 ms
6,676 KB
testcase_09 AC 11 ms
6,676 KB
testcase_10 AC 10 ms
6,676 KB
testcase_11 AC 4 ms
6,676 KB
testcase_12 AC 123 ms
37,992 KB
testcase_13 AC 1,294 ms
141,812 KB
testcase_14 AC 258 ms
37,988 KB
testcase_15 AC 1,023 ms
141,808 KB
testcase_16 AC 733 ms
37,992 KB
testcase_17 AC 1,095 ms
72,588 KB
testcase_18 AC 348 ms
7,808 KB
testcase_19 AC 524 ms
37,992 KB
testcase_20 AC 1,200 ms
141,832 KB
testcase_21 AC 459 ms
12,032 KB
testcase_22 AC 1,461 ms
141,768 KB
testcase_23 AC 1,482 ms
141,768 KB
testcase_24 AC 1,448 ms
141,768 KB
testcase_25 AC 1,470 ms
141,768 KB
testcase_26 AC 1,459 ms
141,768 KB
testcase_27 AC 1,434 ms
141,768 KB
testcase_28 AC 1,440 ms
141,768 KB
testcase_29 AC 1,429 ms
141,768 KB
testcase_30 AC 1,499 ms
141,768 KB
testcase_31 AC 1,451 ms
141,768 KB
testcase_32 AC 111 ms
6,676 KB
testcase_33 AC 111 ms
6,676 KB
testcase_34 AC 129 ms
6,676 KB
testcase_35 AC 134 ms
6,676 KB
testcase_36 AC 132 ms
6,676 KB
testcase_37 AC 1,256 ms
141,768 KB
testcase_38 AC 1,255 ms
141,768 KB
testcase_39 AC 1,314 ms
141,768 KB
testcase_40 AC 1,281 ms
141,768 KB
testcase_41 AC 1,247 ms
141,768 KB
testcase_42 AC 1,339 ms
141,768 KB
testcase_43 AC 1,279 ms
141,768 KB
testcase_44 AC 1,274 ms
141,768 KB
testcase_45 AC 1,266 ms
141,768 KB
testcase_46 AC 1,266 ms
141,768 KB
testcase_47 AC 1,547 ms
141,768 KB
testcase_48 AC 1,567 ms
141,768 KB
testcase_49 AC 1,564 ms
141,768 KB
testcase_50 AC 1,624 ms
141,768 KB
testcase_51 AC 1,573 ms
141,768 KB
testcase_52 AC 1,606 ms
141,768 KB
testcase_53 AC 1,624 ms
141,768 KB
testcase_54 AC 1,639 ms
141,768 KB
testcase_55 AC 1,606 ms
141,768 KB
testcase_56 AC 1,626 ms
141,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define rep(i, n) for(int i=0;i<(n);++i)
#define rep1(i, n) for(int i=1;i<=(n);i++)
#define ll long long
using mint = modint998244353;
using P = pair<ll,ll>;
using lb = long double;
using T = tuple<ll, ll, ll>;
#ifdef LOCAL
#  include <debug_print.hpp>
#  define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#  define dbg(...) (static_cast<void>(0))
#endif

using S = tuple<ll, ll,ll, ll, ll>;
S op(S a, S b){
    auto [m, mm, ma, mma, len] = a;
    auto [m2, mm2, ma2, mma2,len2] = b;
    ll m3 = m + m2;
    ll mm3 = m * m2 + mm + mm2;
    ll ma3 = ma + ma2 + m * (len2-m2);
    ll mma3 = mma + mma2 + m*ma2 + mm * (len2-m2);
    return {m3,mm3,ma3,mma3,len+len2}; 
}

S e(){
    return {0,0,0,0,0};
}

int main()
{
    int n;
    string s;
    cin >> n >> s;
    int q;
    cin >> q;
    segtree<S, op, e> seg(n);
    vector<segtree<S, op, e>> cnt(26, seg);
    rep(i,n){
        rep(j,26){
            if(s[i]-'A'==j){
                cnt[j].set(i,{1,0,0,0,1});
            }
            else{
                cnt[j].set(i,{0,0,0,0,1});
            }
        }
    }
    rep(_,q){
        int t;
        cin >> t;
        if(t==1){
            int x;
            char c;
            cin >> x >> c;
            --x;
            rep(j,26){
                cnt[j].set(x,{0,0,0,0,1});
            }
            s[x] = c;
            rep(j,26){
                if(j==s[x]-'A'){
                    cnt[j].set(x,{1,0,0,0,1});
                }
                else{
                    cnt[j].set(x,{0,0,0,0,1});
                }
            }
        }else{
            int l, r;
            cin >> l >> r;
            --l;
            ll ans = 0;
            rep(i,26){
                S p = cnt[i].prod(l, r);
                auto [a,b,c,d, e] = p;
                ans += d;
            }
            cout << ans << endl;
        }
    }
    return 0;
}
0