結果
問題 | No.2761 Substitute and Search |
ユーザー |
![]() |
提出日時 | 2024-05-20 22:24:14 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,360 ms / 4,000 ms |
コード長 | 2,196 bytes |
コンパイル時間 | 4,610 ms |
コンパイル使用メモリ | 263,288 KB |
最終ジャッジ日時 | 2025-02-21 16:21:18 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 13 |
ソースコード
#include <bits/stdc++.h>#include <atcoder/all>using namespace std;using namespace atcoder;using m1 = modint998244353;using m2 = modint1000000007;using P = pair<m1, m2>;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, a.second + b.second};}P e() {return {0, 0};}int main() {int n, l, q;cin >> n >> l >> q;vector<string> s(n);for (int i = 0; i < n; i++) {cin >> s[i];}m1 b1 = xorshift();m2 b2 = xorshift();vector<m1> p1(l, 1);vector<m2> p2(l, 1);for (int i = 1; i < l; i++) {p1[i] = p1[i - 1] * b1;p2[i] = p2[i - 1] * b2;}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++) {int x = s[i][j] - 'a' + 1;m1 h1 = p1[j] * x;m2 h2 = p2[j] * x;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--;int x = d - 'a' + 1;for (int i = 0; i < n; i++) {if (s[i][k] == c) {m1 h1 = p1[k] * x;m2 h2 = p2[k] * x;seg[i].set(k, {h1, h2});s[i][k] = d;}}} else {string pre;cin >> pre;int len = pre.size();m1 h1 = 0;m2 h2 = 0;for (int i = 0; i < len; i++) {int x = pre[i] - 'a' + 1;h1 += p1[i] * x;h2 += p2[i] * x;}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;}}}