結果

問題 No.1725 [Cherry 3rd Tune D] 無言の言葉
ユーザー square1001square1001
提出日時 2021-10-29 21:46:17
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 196 ms / 4,000 ms
コード長 2,043 bytes
コンパイル時間 978 ms
コンパイル使用メモリ 86,812 KB
実行使用メモリ 24,408 KB
最終ジャッジ日時 2024-04-16 14:34:05
合計ジャッジ時間 6,597 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 6 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 16 ms
5,376 KB
testcase_07 AC 6 ms
5,376 KB
testcase_08 AC 11 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 6 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 14 ms
5,376 KB
testcase_13 AC 15 ms
5,376 KB
testcase_14 AC 117 ms
5,376 KB
testcase_15 AC 17 ms
5,376 KB
testcase_16 AC 24 ms
5,376 KB
testcase_17 AC 42 ms
5,376 KB
testcase_18 AC 139 ms
5,376 KB
testcase_19 AC 37 ms
5,376 KB
testcase_20 AC 15 ms
5,376 KB
testcase_21 AC 128 ms
5,376 KB
testcase_22 AC 132 ms
10,240 KB
testcase_23 AC 136 ms
9,344 KB
testcase_24 AC 90 ms
7,552 KB
testcase_25 AC 156 ms
13,684 KB
testcase_26 AC 128 ms
11,520 KB
testcase_27 AC 114 ms
15,488 KB
testcase_28 AC 176 ms
14,920 KB
testcase_29 AC 170 ms
14,128 KB
testcase_30 AC 148 ms
16,332 KB
testcase_31 AC 101 ms
9,344 KB
testcase_32 AC 186 ms
21,420 KB
testcase_33 AC 190 ms
22,232 KB
testcase_34 AC 186 ms
20,724 KB
testcase_35 AC 182 ms
18,600 KB
testcase_36 AC 185 ms
20,244 KB
testcase_37 AC 191 ms
5,376 KB
testcase_38 AC 190 ms
5,376 KB
testcase_39 AC 189 ms
5,376 KB
testcase_40 AC 188 ms
5,376 KB
testcase_41 AC 196 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 26 ms
24,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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, int)> calc = [&](int layer, long long l, long long r, int rev) {
			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 ? (rev == 0 ? XS[id][pr - l] - XS[id][pl - l] : XS[id][LX - (pl - l)] - XS[id][LX - (pr - l)]) : 0LL);
			}
			long long mp1 = l + LF[layer - 1];
			long long mp2 = r - LF[layer - 1];
			long long res1 = calc(layer - 1, l, mp1, 0);
			long long res2 = calc(layer - 1, mp2, r, 1);
			long long res3 = 0;
			long long cl = max(mp1, (long long)(L)), cr = min(mp2, (long long)(R));
			if (cl < cr) {
				res3 = (rev == 0 ? YS[id][cr - mp1] - YS[id][cl - mp1] : YS[id][LY - (cl - mp1)] - YS[id][LY - (cr - mp1)]);
			}
			return res1 + res2 + res3;
		};
		long long ans = calc(int(LF.size()) - 1, 0, LF.back(), 0);
		cout << ans << endl;
	}
	return 0;
}
0