結果
| 問題 |
No.2761 Substitute and Search
|
| コンテスト | |
| ユーザー |
Tatsu_mr
|
| 提出日時 | 2024-05-20 19:37:51 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,393 bytes |
| コンパイル時間 | 4,486 ms |
| コンパイル使用メモリ | 258,360 KB |
| 最終ジャッジ日時 | 2025-02-21 16:18:35 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 2 TLE * 1 -- * 10 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using P = pair<long long, long long>;
long long m1 = 1000000007, m2 = 1000000009;
unsigned int xorshift() {
static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
unsigned int t = (x ^ (x << 11));
x = y;
y = z;
z = w;
return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
P op(P a, P b) {
return {(a.first + b.first) % m1, (a.second + b.second) % m2};
}
P e() {
return {0LL, 0LL};
}
int main() {
int n, l, q;
cin >> n >> l >> q;
vector<string> s(n);
for (int i = 0; i < n; i++) {
cin >> s[i];
}
long long b1 = xorshift() % m1, b2 = xorshift() % m2;
vector<long long> p1(3010), p2(3010);
p1[0] = p2[0] = 1LL;
for (int i = 1; i < 3010; i++) {
p1[i] = p1[i - 1] * b1 % m1;
p2[i] = p2[i - 1] * b2 % m2;
}
vector<segtree<P, op, e>> seg(n, segtree<P, op, e>(l));
for (int i = 0; i < n; i++) {
for (int j = 0; j < l; j++) {
long long x = s[i][j] - 'a' + 1LL;
long long h1 = (p1[j] * x) % m1;
long long h2 = (p2[j] * x) % m2;
seg[i].set(j, {h1, h2});
}
}
while (q--) {
int t;
cin >> t;
if (t == 1) {
int k;
char c, d;
cin >> k >> c >> d;
k--;
long long x = d - 'a' + 1LL;
for (int i = 0; i < n; i++) {
if (s[i][k] == c) {
long long h1 = p1[k] * x % m1;
long long h2 = p2[k] * x % m2;
seg[i].set(k, {h1, h2});
s[i][k] = d;
}
}
} else {
string pre;
cin >> pre;
int len = pre.size();
long long h1 = 0LL, h2 = 0LL;
for (int i = 0; i < len; i++) {
long long x = pre[i] - 'a' + 1LL;
h1 += (p1[i] * x) % m1;
h1 %= m1;
h2 += (p2[i] * x) % m2;
h2 %= m2;
}
int ans = 0;
for (int i = 0; i < n; i++) {
P cur = seg[i].prod(0, len);
if (cur.first == h1 && cur.second == h2) {
ans++;
}
}
cout << ans << endl;
}
}
}
Tatsu_mr