結果

問題 No.2761 Substitute and Search
ユーザー Tatsu_mrTatsu_mr
提出日時 2024-05-20 19:53:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,452 bytes
コンパイル時間 4,727 ms
コンパイル使用メモリ 272,756 KB
実行使用メモリ 279,700 KB
最終ジャッジ日時 2024-05-20 19:53:20
合計ジャッジ時間 15,393 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,892 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 TLE -
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

using lint = long long;

lint 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)));
}

lint op1(lint a, lint b) {
    return (a + b) % m1;
}

lint op2(lint a, lint b) {
    return (a + b) % m2;
}

lint e() {
    return 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];
    }
    lint b1 = xorshift() % m1, b2 = xorshift() % m2;
    vector<lint> 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<lint, op1, e>> seg1(n, segtree<lint, op1, e>(l));
    vector<segtree<lint, op2, e>> seg2(n, segtree<lint, op2, e>(l));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            lint x = s[i][j] - 'a' + 1LL;
            lint h1 = p1[j] * x % m1;
            lint h2 = p2[j] * x % m2;
            seg1[i].set(j, h1);
            seg2[i].set(j, h2);
        }
    }
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            int k;
            char c, d;
            cin >> k >> c >> d;
            k--;
            lint x = d - 'a' + 1LL;
            for (int i = 0; i < n; i++) {
                if (s[i][k] == c) {
                    lint h1 = p1[k] * x % m1;
                    lint h2 = p2[k] * x % m2;
                    seg1[i].set(k, h1);
                    seg2[i].set(k, h2);
                    s[i][k] = d;
                }
            }
        } else {
            string pre;
            cin >> pre;
            int len = pre.size();
            lint h1 = 0LL, h2 = 0LL;
            for (int i = 0; i < len; i++) {
                lint 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++) {
                if (seg1[i].prod(0, len) == h1 && seg2[i].prod(0, len) == h2) {
                    ans++;
                }
            }
            cout << ans << endl;
        }
    }
}
0