結果

問題 No.1725 [Cherry 3rd Tune D] 無言の言葉
ユーザー rtyurtyu
提出日時 2021-11-01 14:08:59
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 4,000 ms
コード長 1,160 bytes
コンパイル時間 873 ms
コンパイル使用メモリ 69,232 KB
実行使用メモリ 24,116 KB
最終ジャッジ日時 2024-04-18 09:27:33
合計ジャッジ時間 4,081 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 21 ms
5,376 KB
testcase_15 AC 5 ms
5,376 KB
testcase_16 AC 5 ms
5,376 KB
testcase_17 AC 10 ms
5,376 KB
testcase_18 AC 25 ms
5,376 KB
testcase_19 AC 7 ms
5,376 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 23 ms
5,376 KB
testcase_22 AC 30 ms
10,240 KB
testcase_23 AC 35 ms
9,600 KB
testcase_24 AC 19 ms
7,680 KB
testcase_25 AC 32 ms
13,696 KB
testcase_26 AC 30 ms
11,648 KB
testcase_27 AC 23 ms
15,360 KB
testcase_28 AC 37 ms
14,464 KB
testcase_29 AC 38 ms
14,080 KB
testcase_30 AC 36 ms
16,384 KB
testcase_31 AC 23 ms
9,600 KB
testcase_32 AC 43 ms
21,248 KB
testcase_33 AC 46 ms
21,760 KB
testcase_34 AC 44 ms
20,352 KB
testcase_35 AC 42 ms
18,432 KB
testcase_36 AC 43 ms
19,968 KB
testcase_37 AC 45 ms
5,376 KB
testcase_38 AC 43 ms
5,376 KB
testcase_39 AC 44 ms
5,376 KB
testcase_40 AC 42 ms
5,376 KB
testcase_41 AC 41 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 13 ms
24,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;

int n, m, sx[100009][26], sy[100009][26];

int ps(int xc, int yc, int r, int p)
{
	if (r < 1) return 0;
	if (!yc) return sx[r][p];
	int txc = xc / 2, tyc = (yc - 1) / 2;
	if (txc * n + tyc * m >= r) return ps(txc, tyc, r, p);
	else if (txc * n + (tyc + 1) * m >= r) return sx[n][p] * txc + sy[m][p] * tyc + sy[r - (txc * n + tyc * m)][p];
	else return sx[n][p] * xc + sy[m][p] * yc - ps(txc, tyc, xc * n + yc * m - r, p);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string x, y; cin >> x >> y;
	n = x.length(); m = y.length();
	x = "." + x; y = "." + y;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < 26; j++)
			sx[i][j] = sx[i - 1][j];
		sx[i][(int)(x[i] - 'a')]++;
	}
	for (int i = 1; i <= m; i++) {
		for (int j = 0; j < 26; j++)
			sy[i][j] = sy[i - 1][j];
		sy[i][(int)(y[i] - 'a')]++;
	}
	int q; cin >> q;
	for (int i = 0; i < q; i++) {
		int l, r; char p; cin >> l >> r >> p;
		int xc = 1, yc = 0;
		while (xc * n + yc * m < r) {
			xc *= 2;
			yc = yc * 2 + 1;
		}
		cout << ps(xc, yc, r, (int)(p - 'a')) - ps(xc, yc, l - 1, (int)(p - 'a')) << '\n';
	}
	return 0;
}
0