結果
問題 |
No.2761 Substitute and Search
|
ユーザー |
![]() |
提出日時 | 2024-05-19 13:58:16 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,969 bytes |
コンパイル時間 | 4,230 ms |
コンパイル使用メモリ | 259,096 KB |
最終ジャッジ日時 | 2025-02-21 15:55:50 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 1 TLE * 1 -- * 11 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; #define rep(i, n) for(int i=0;i<(n);++i) #define rep1(i, n) for(int i=1;i<=(n);i++) #define ll long long using mint = modint998244353; using P = pair<ll,ll>; using lb = long double; using T = tuple<ll, ll, ll>; #ifdef LOCAL # include <debug_print.hpp> # define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__) #else # define dbg(...) (static_cast<void>(0)) #endif ////segtreeに乗せる用 long long mod = 2147483647; struct S { long long hash, pow; }; S op(S a, S b){ long long na = a.hash * b.pow + b.hash; na %= mod; return {na, (a.pow * b.pow) % mod}; } S e(){ return {0,1}; } int main() { int n, l, q; cin >> n >> l >> q; segtree<S, op, e> tmp(l); vector<segtree<S, op, e>> seg(n, tmp); vector<string> s(n); rep(i,n) { cin >> s[i]; rep(j,l) { S t; t.hash = s[i][j] - 'a'; t.pow = 10; seg[i].set(j, t); } } while(q--) { int t; cin >> t; if(t==1) { int k; char c, d; cin >> k >> c >> d; --k; rep(i,n) { if(s[i][k]==c) { s[i][k] = d; S r; r.hash = d - 'a'; r.pow = 10; seg[i].set(k, r); } } } else{ string t; cin >> t; int ans = 0; int m = t.size(); segtree<S, op, e> h(m); rep(i,m) { S r; r.hash = t[i]- 'a'; r.pow = 10; h.set(i, r); } ll hs = h.prod(0,m).hash; rep(i,n) { if(seg[i].prod(0, m).hash == hs) ans++; } cout << ans << "\n"; } } return 0; }