結果
問題 | No.2761 Substitute and Search |
ユーザー | shobonvip |
提出日時 | 2024-05-17 22:26:06 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2,903 ms / 4,000 ms |
コード長 | 5,261 bytes |
コンパイル時間 | 5,018 ms |
コンパイル使用メモリ | 284,516 KB |
実行使用メモリ | 163,156 KB |
最終ジャッジ日時 | 2024-05-17 22:26:38 |
合計ジャッジ時間 | 25,438 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 29 ms
27,212 KB |
testcase_01 | AC | 30 ms
27,340 KB |
testcase_02 | AC | 30 ms
27,344 KB |
testcase_03 | AC | 28 ms
27,340 KB |
testcase_04 | AC | 1,943 ms
162,900 KB |
testcase_05 | AC | 2,903 ms
163,152 KB |
testcase_06 | AC | 719 ms
163,024 KB |
testcase_07 | AC | 2,018 ms
163,148 KB |
testcase_08 | AC | 719 ms
163,024 KB |
testcase_09 | AC | 2,012 ms
163,152 KB |
testcase_10 | AC | 689 ms
163,020 KB |
testcase_11 | AC | 2,007 ms
163,152 KB |
testcase_12 | AC | 1,398 ms
163,024 KB |
testcase_13 | AC | 1,388 ms
163,156 KB |
testcase_14 | AC | 1,375 ms
163,028 KB |
testcase_15 | AC | 1,381 ms
163,024 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; //* ATCODER #include<atcoder/all> using namespace atcoder; typedef modint998244353 mint; //*/ typedef dynamic_modint<0> mint1; typedef dynamic_modint<1> mint2; /* BOOST MULTIPRECISION /* BOOST MULTIPRECISION #include<boost/multiprecision/cpp_int.hpp> using namespace boost::multiprecision; //*/ typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) template <typename T> bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template <typename T> bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template <typename T> T max(vector<T> &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]); return ret; } template <typename T> T min(vector<T> &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]); return ret; } template <typename T> T sum(vector<T> &a){ T ret = 0; for (int i=0; i<(int)a.size(); i++) ret += a[i]; return ret; } vector<mint> poly_inv(vector<mint> &a, int M = -314159265){ if (M == -314159265) M = (int)a.size(); else if (M <= 0) return {}; int n = a.size(); mint r = a[0].pow((ll)(mint::mod())-2); int m = 1; vector<mint> res = {r}; while (m < M){ vector<mint> f = a; f.resize(2 * m); vector<mint> g = res; g.resize(2 * m); internal::butterfly(f); internal::butterfly(g); for (int i=0; i<2*m; i++){ f[i] = f[i] * g[i]; } internal::butterfly_inv(f); for (int i=0; i<m; i++){ f[i] = f[i + m]; } for (int i=0; i<m; i++){ f[i + m] = 0; } internal::butterfly(f); for (int i=0; i<2*m; i++){ f[i] = f[i] * g[i]; } internal::butterfly_inv(f); mint iz = mint(2*m).inv(); iz = -iz * iz; for (int i=0; i<m; i++){ f[i] = f[i] * iz; } res.insert(res.end(), f.begin(), f.begin()+m); m <<= 1; } res.resize(M); return res; } //defmodfact const int COMinitMAX = 998244; mint fact[COMinitMAX+1], factinv[COMinitMAX+1]; void modfact(){ fact[0] = 1; for (int i=1; i<=COMinitMAX; i++){ fact[i] = fact[i-1] * i; } factinv[COMinitMAX] = fact[COMinitMAX].inv(); for (int i=COMinitMAX-1; i>=0; i--){ factinv[i] = factinv[i+1] * (i+1); } } mint cmb(int a, int b){ if (a<b || b<0) return mint(0); return fact[a]*factinv[b]*factinv[a-b]; } //-------- vector<mint> poly_log(vector<mint> &a, int M = -314159265){ if (M == -314159265) M = (int)a.size(); else if (M <= 0) return {}; int n = a.size(); if (n == 1) return vector<mint>(M, 0); vector<mint> b(n-1); for (int i=0; i<n-1; i++){ b[i] = a[i+1] * (i+1); } vector<mint> t = convolution<mint>(b, poly_inv(a, M)); vector<mint> ret(M); for (int i=0; i<M-1; i++){ ret[i+1] = t[i] * factinv[i+1] * fact[i]; } return ret; } vector<mint> poly_exp(vector<mint> &a, int M = -314159265){ if (M == -314159265) M = (int)a.size(); else if (M <= 0) return {}; int n = a.size(); int m = 1; vector<mint> res = {1}; while (m < M){ vector<mint> f(2*m); for (int i=0; i<min(n, 2*m); i++) f[i] = a[i]; vector<mint> v = poly_log(res, 2*m); vector<mint> w(2*m); for (int i=0; i<2*m; i++) w[i] = f[i] - v[i]; w[0] += 1; vector<mint> g = convolution<mint>(res, w); res.insert(res.end(), g.begin()+m, g.begin()+2*m); m <<= 1; } res.resize(M); return res; } mint1 b1l[2034567]; mint2 b2l[2034567]; struct S{ mint1 m1; mint2 m2; ll len; }; S op(S a, S b){ return { a.m1 * b1l[b.len] + b.m1, a.m2 * b2l[b.len] + b.m2, a.len + b.len }; } S e(){ return {0, 0, 0}; } // isprime bool isprime(ll n){ if (n == 1) return false; for (ll i = 2; i * i <= n; i++){ if (n % i == 0) return false; } return true; } // importrandom // don't forget randomjumon // and also isprime ll RandomMod(ll l, ll r){ ll ret = l + rand() % (r - l); while (!isprime(ret)) ret = l + rand() % (r - l); return ret; } ll randrange(ll l, ll r){ return l + rand() % (r - l); } // ----- int main(){ srand((unsigned)time(NULL)); // Rolling Hash // don't forget randomjumon and importrandom int mod1 = RandomMod(7e8, 1e9); int mod2; do{ mod2 = RandomMod(7e8, 1e9); }while(mod2 == mod1); mint1::set_mod(mod1); mint2::set_mod(mod2); mint1 b1 = randrange(100, 200); mint2 b2 = randrange(100, 200); b1l[0] = 1; for (int i=0; i<2000000; i++){ b1l[i+1] = b1l[i] * b1; } b2l[0] = 1; for (int i=0; i<2000000; i++){ b2l[i+1] = b2l[i] * b2; } // ----- int n, l, q; cin >> n >> l >> q; vector<string> s(n); rep(i,0,n){ cin >> s[i]; } vector<segtree<S,op,e>> seg(n, segtree<S,op,e>(l)); rep(i,0,n){ rep(j,0,l){ seg[i].set(j, {s[i][j]-'a'+1, s[i][j]-'a'+1, 1}); } } while(q--){ int t; cin >> t; if (t == 1){ int k; cin >> k; k--; char c, d; cin >> c >> d; rep(i,0,n){ if (s[i][k] == c){ s[i][k] = d; seg[i].set(k, {s[i][k]-'a'+1, s[i][k]-'a'+1, 1}); } } }else{ string t; cin >> t; int m = t.size(); S gg = e(); rep(i,0,m){ gg = op(gg, {t[i]-'a'+1, t[i]-'a'+1, 1}); } int ret = 0; rep(i,0,n){ S val = seg[i].prod(0, m); if (val.m1 == gg.m1 && val.m2 == gg.m2) ret++; } cout << ret << '\n'; } } }