結果

問題 No.2554 MMA文字列2 (Query Version)
ユーザー dyktr_06dyktr_06
提出日時 2023-10-27 02:05:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 967 bytes
コンパイル時間 2,392 ms
コンパイル使用メモリ 207,356 KB
実行使用メモリ 15,996 KB
最終ジャッジ日時 2023-10-27 02:05:22
合計ジャッジ時間 10,319 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

long long naive(string s){
    int n = s.size();
    long long ans = 0;
    vector<vector<long long>> sum(n + 1, vector<long long>(26));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 26; j++){
            sum[i + 1][j] += sum[i][j];
        }
        sum[i + 1][s[i] - 'A']++;
    }
    for(int i = n - 1; i >= 0; i--){
        for(int j = 0; j < 26; j++){
            if(s[i] - 'A' == j) continue;
            ans += sum[i][j] * (sum[i][j] - 1) / 2;
        }
    }
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, q;
    string s;
    cin >> n >> s >> q;
    
    while(q--){
        int t; cin >> t;
        if(t == 1){
            int x;
            char c;
            cin >> x >> c; x--;
            s[x] = c;
        }else{
            int l, r;
            cin >> l >> r; l--;
            cout << naive(s.substr(l, r - l)) << endl;
        }
    }
}
0