結果

問題 No.2554 MMA文字列2 (Query Version)
ユーザー maeshunmaeshun
提出日時 2023-11-26 01:29:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,980 bytes
コンパイル時間 4,490 ms
コンパイル使用メモリ 274,120 KB
実行使用メモリ 72,680 KB
最終ジャッジ日時 2023-11-26 01:30:01
合計ジャッジ時間 40,284 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 4 ms
6,548 KB
testcase_03 AC 5 ms
6,548 KB
testcase_04 AC 7 ms
6,548 KB
testcase_05 AC 7 ms
6,548 KB
testcase_06 AC 5 ms
6,548 KB
testcase_07 AC 5 ms
6,548 KB
testcase_08 AC 4 ms
6,548 KB
testcase_09 AC 7 ms
6,548 KB
testcase_10 AC 6 ms
6,548 KB
testcase_11 AC 4 ms
6,548 KB
testcase_12 AC 76 ms
20,712 KB
testcase_13 WA -
testcase_14 AC 155 ms
20,708 KB
testcase_15 WA -
testcase_16 AC 456 ms
20,712 KB
testcase_17 WA -
testcase_18 AC 217 ms
6,548 KB
testcase_19 AC 352 ms
20,712 KB
testcase_20 WA -
testcase_21 AC 272 ms
7,808 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 95 ms
6,548 KB
testcase_33 AC 93 ms
6,548 KB
testcase_34 AC 105 ms
6,548 KB
testcase_35 AC 107 ms
6,548 KB
testcase_36 AC 107 ms
6,548 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
権限があれば一括ダウンロードができます

ソースコード

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<int, int,int, int, int>;
S op(S a, S b){
    auto [m, mm, ma, mma, len] = a;
    auto [m2, mm2, ma2, mma2,len2] = b;
    int m3 = m + m2;
    int mm3 = m * m2 + mm + mm2;
    int ma3 = ma + ma2 + m * (len2-m2);
    int 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