結果
問題 | No.1725 [Cherry 3rd Tune D] 無言の言葉 |
ユーザー | square1001 |
提出日時 | 2021-10-29 21:42:24 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,894 bytes |
コンパイル時間 | 1,002 ms |
コンパイル使用メモリ | 86,640 KB |
実行使用メモリ | 24,292 KB |
最終ジャッジ日時 | 2024-10-07 10:35:19 |
合計ジャッジ時間 | 6,221 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
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 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | AC | 168 ms
5,248 KB |
testcase_38 | AC | 164 ms
5,248 KB |
testcase_39 | AC | 169 ms
5,248 KB |
testcase_40 | AC | 168 ms
5,248 KB |
testcase_41 | AC | 168 ms
5,248 KB |
testcase_42 | AC | 2 ms
5,248 KB |
testcase_43 | AC | 24 ms
24,292 KB |
ソースコード
#include <string> #include <vector> #include <iostream> #include <algorithm> #include <functional> using namespace std; int main() { string X, Y; int Q; cin >> X >> Y >> Q; int LX = X.size(), LY = Y.size(); vector<long long> LF = { LX }; while (LF.back() <= 1000000000) { LF.push_back(LF.back() * 2 + LY); } vector<vector<int> > XS(26, vector<int>(LX + 1)); vector<vector<int> > YS(26, vector<int>(LY + 1)); for (int i = 0; i < LX; ++i) { XS[X[i] - 'a'][i + 1]++; } for (int i = 0; i < LY; ++i) { YS[Y[i] - 'a'][i + 1]++; } for (int i = 0; i < 26; ++i) { for (int j = 0; j < LX; ++j) { XS[i][j + 1] += XS[i][j]; } for (int j = 0; j < LY; ++j) { YS[i][j + 1] += YS[i][j]; } } vector<vector<long long> > CF(LF.size(), vector<long long>(26)); for (int i = 0; i < 26; ++i) { CF[0][i] = XS[i][LX]; } for (int i = 1; i < int(LF.size()); ++i) { for (int j = 0; j < 26; ++j) { CF[i][j] = CF[i - 1][j] * 2 + YS[j][LY]; } } for (int i = 0; i < Q; ++i) { int L, R; string C; cin >> L >> R >> C; --L; int id = C[0] - 'a'; function<long long(int, long long, long long)> calc = [&](int layer, long long l, long long r) { if (L <= l && r <= R) { return CF[layer][id]; } if (R <= l || r <= L) { return 0LL; } if (layer == 0) { long long pl = max(l, (long long)(L)), pr = min(r, (long long)(R)); return (l < r ? XS[id][pr - l] - XS[id][pl - l] : 0LL); } long long mp1 = l + LF[layer - 1]; long long mp2 = r - LF[layer - 1]; long long res1 = calc(layer - 1, l, mp1); long long res2 = calc(layer - 1, mp2, r); long long res3 = 0; long long cl = max(mp1, (long long)(L)), cr = min(mp2, (long long)(R)); if (cl < cr) { res3 = YS[id][cr - mp1] - YS[id][cl - mp1]; } return res1 + res2 + res3; }; long long ans = calc(int(LF.size()) - 1, 0, LF.back()); cout << ans << endl; } return 0; }