結果
| 問題 |
No.1725 [Cherry 3rd Tune D] 無言の言葉
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-11-01 14:08:59 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 46 ms / 4,000 ms |
| コード長 | 1,160 bytes |
| コンパイル時間 | 636 ms |
| コンパイル使用メモリ | 69,216 KB |
| 実行使用メモリ | 23,980 KB |
| 最終ジャッジ日時 | 2024-10-10 02:43:22 |
| 合計ジャッジ時間 | 4,328 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 42 |
ソースコード
#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;
}