結果

問題 No.1725 [Cherry 3rd Tune D] 無言の言葉
ユーザー 👑 tatyamtatyam
提出日時 2021-10-16 18:13:12
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3,414 ms / 4,000 ms
コード長 1,307 bytes
コンパイル時間 3,642 ms
コンパイル使用メモリ 281,864 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 13:48:30
合計ジャッジ時間 39,933 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 5 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 14 ms
5,376 KB
testcase_07 AC 7 ms
5,376 KB
testcase_08 AC 10 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 7 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 27 ms
5,376 KB
testcase_13 AC 34 ms
5,376 KB
testcase_14 AC 274 ms
5,376 KB
testcase_15 AC 41 ms
5,376 KB
testcase_16 AC 62 ms
5,376 KB
testcase_17 AC 125 ms
5,376 KB
testcase_18 AC 329 ms
5,376 KB
testcase_19 AC 82 ms
5,376 KB
testcase_20 AC 21 ms
5,376 KB
testcase_21 AC 258 ms
5,376 KB
testcase_22 AC 1,673 ms
5,376 KB
testcase_23 AC 937 ms
5,376 KB
testcase_24 AC 626 ms
5,376 KB
testcase_25 AC 2,161 ms
5,376 KB
testcase_26 AC 1,888 ms
5,376 KB
testcase_27 AC 1,478 ms
5,376 KB
testcase_28 AC 2,109 ms
5,376 KB
testcase_29 AC 2,008 ms
5,376 KB
testcase_30 AC 2,009 ms
5,376 KB
testcase_31 AC 873 ms
5,376 KB
testcase_32 AC 3,301 ms
5,376 KB
testcase_33 AC 3,414 ms
5,376 KB
testcase_34 AC 3,167 ms
5,376 KB
testcase_35 AC 2,787 ms
5,376 KB
testcase_36 AC 3,095 ms
5,376 KB
testcase_37 AC 158 ms
5,376 KB
testcase_38 AC 159 ms
5,376 KB
testcase_39 AC 160 ms
5,376 KB
testcase_40 AC 158 ms
5,376 KB
testcase_41 AC 159 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 12 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma optimize("avx2")
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;


int main(){
    using A = valarray<i64>;
    string X, Y;
    cin >> X >> Y;
    for(char& c : X) c -= 'a';
    for(char& c : Y) c -= 'a';
    A countX(i64{}, 27), countY(i64{}, 27);
    auto accX = [&](i64 R, char C) -> i64 {
        return count(X.begin(), X.begin() + R, C);
    };
    auto accY = [&](i64 R, char C) -> i64 {
        return count(Y.begin(), Y.begin() + R, C);
    };
    for(i64 i = 0; i < 26; i++){
        countX[i] = accX(X.size(), i);
        countY[i] = accY(Y.size(), i);
    }
    countX[26] = X.size();
    countY[26] = Y.size();
    vector<A> countF = {countX};
    for(i64 i = 0; i < 30; i++) countF.push_back(countF.back() * 2 + countY);
    function<i64(i64, i64, char)> count = [&](i64 N, i64 R, char C){
        if(N == 0) return accX(R, C);
        if(R < countF[N - 1][26]) return count(N - 1, R, C);
        if(R > countF[N - 1][26] + Y.size()) return countF[N][C] - count(N - 1, countF[N][26] - R, C);
        return countF[N - 1][C] + accY(R - countF[N - 1][26], C);
    };
    i64 Q;
    cin >> Q;
    while(Q--){
        i64 L, R;
        char C;
        cin >> L >> R >> C;
        L--;
        C -= 'a';
        cout << count(30, R, C) - count(30, L, C) << '\n';
    }
}
0