結果
問題 | No.2761 Substitute and Search |
ユーザー | wingu |
提出日時 | 2024-09-27 21:09:40 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 3,921 ms / 4,000 ms |
コード長 | 5,198 bytes |
コンパイル時間 | 3,664 ms |
コンパイル使用メモリ | 263,516 KB |
実行使用メモリ | 139,008 KB |
最終ジャッジ日時 | 2024-09-27 21:10:16 |
合計ジャッジ時間 | 30,395 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 3,921 ms
138,880 KB |
testcase_05 | AC | 2,657 ms
138,880 KB |
testcase_06 | AC | 703 ms
139,008 KB |
testcase_07 | AC | 2,986 ms
138,880 KB |
testcase_08 | AC | 697 ms
138,880 KB |
testcase_09 | AC | 2,992 ms
138,880 KB |
testcase_10 | AC | 707 ms
138,880 KB |
testcase_11 | AC | 3,164 ms
138,880 KB |
testcase_12 | AC | 1,992 ms
138,880 KB |
testcase_13 | AC | 1,834 ms
138,880 KB |
testcase_14 | AC | 1,914 ms
138,752 KB |
testcase_15 | AC | 1,839 ms
139,008 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #include <atcoder/modint> using namespace atcoder; #ifdef DEFINED_ONLY_IN_LOCAL #include <dump.hpp> #define dump(...) cpp_dump(__VA_ARGS__) #else #undef dump #define dump(...) #endif #define rep1(a) for (int i = 0; i < a; i++) #define rep2(i, a) for (int i = 0; i < a; i++) #define rep3(i, a, b) for (int i = a; i < b; i++) #define rep4(i, a, b, c) for (int i = a; i < b; i += c) #define overloadRep(a, b, c, d, e, ...) e #define rep(...) overloadRep(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define endl '\n' #define INT(...) int __VA_ARGS__; input(__VA_ARGS__) #define LL(...) ll __VA_ARGS__; input(__VA_ARGS__) using ll = long long; using ull = unsigned long long; const int inf = 1e9; const ll INF = 1e18; const int dx[4] = {0, 1, 0, -1}; const int dy[4] = {1, 0, -1, 0}; const int ddx[8] = {1, 0, -1, 0, 1, -1, 1, -1}; const int ddy[8] = {0, 1, 0, -1, 1, -1, -1, 1}; struct cincout {cincout() {ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15);}} init; template <class... T> void input(T&... a) {(cin >> ... >> a);} template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;} template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;} template <class T1, class T2> istream& operator>>(istream& is, pair<T1, T2>& p) {is >> p.first >> p.second; return is;} template <class T1, class T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) {os << p.first << " " << p.second << '\n'; return os;} template <class T> istream& operator>>(istream& is, vector<T>& v) {for (T& in : v) {is >> in;} return is;} template <class T> ostream& operator<<(ostream& os, const vector<T>& v) {rep(i, (int)v.size()) {os << v[i] << " \n"[i + 1 == (int)v.size()];} return os;} template <class T> istream& operator>>(istream& is, vector<vector<T>>& vv) {for (vector<T>& v : vv) {is >> v;} return is;} template <class T> ostream& operator<<(ostream& os, vector<vector<T>>& vv) {for (vector<T>& v : vv) {os << v;} return os;} template <class T> inline T max(vector<T> x) {return *max_element(x.begin(), x.end());} template <class T> inline T min(vector<T> x) {return *min_element(x.begin(), x.end());} template <class T> inline T sum(vector<T> x) {return reduce(x.begin(), x.end());} template <class... T> constexpr auto min(T... a) {return min(initializer_list<common_type_t<T...>>{a...});} template <class... T> constexpr auto max(T... a) {return max(initializer_list<common_type_t<T...>>{a...});} inline bool bit(ll x, int p) {return (x >> p) & 1;} inline bool out(int ni, int nj, int h, int w) {return (ni < 0 or ni >= h or nj < 0 or nj >= w);} inline int pc(ll x) {return __builtin_popcountll(x);} void Yes(bool judge = true) {cout << (judge ? "Yes" : "No") << endl;} void No(bool judge = true) {cout << (judge ? "No" : "Yes") << endl;} using namespace std; #include <atcoder/segtree> random_device rd; mt19937_64 rnd(rd()); static constexpr long long mod = (1LL << 61) - 1; static const long long base = rnd() % (mod - 4) + 2; using D = pair<long long, long long>; D op(D l, D r) { auto [a, b] = l; auto [c, d] = r; __int128_t x = (__int128_t)a * d + c; return D(x % mod, ((__int128_t)b * d) % mod); } D e() { return D(0, 1); } D op_(D l, D r) { auto [a, b] = l; auto [c, d] = r; __int128_t x = (__int128_t)c * b + a; return D(x % mod, ((__int128_t)b * d) % mod); } struct RollingHashTree { segtree<D, op, e> seg; segtree<D, op_, e> rseg; bool reverse; explicit RollingHashTree(const string &s = "", bool reverse_ = false) : reverse(reverse_) { int n = s.size(); seg = segtree<D, op, e>(n); if (reverse) rseg = segtree<D, op_, e>(n); rep(i, n) { seg.set(i, D(s[i], base)); if (reverse) rseg.set(i, D(s[i], base)); } } inline void set(int i, char c) { seg.set(i, D(c, base)); if (reverse) rseg.set(i, D(c, base)); } inline long long get(int l, int r) { auto [a, b] = seg.prod(l, r); return a; } inline long long rget(int l, int r) { auto [a, b] = rseg.prod(l, r); return a; } }; int main() { int n, l, q; cin >> n >> l >> q; vector<string> s(n); cin >> s; vector<RollingHashTree> rolling_hash(n); rep(i, n) { rolling_hash[i] = RollingHashTree(s[i]); } while (q--) { int type; cin >> type; if (type == 1) { int k; char c, d; cin >> k >> c >> d; k--; rep(i, n) { if (s[i][k] == c) { s[i][k] = d; rolling_hash[i].set(k, d); } } } else { string t; cin >> t; int m = t.size(); RollingHashTree rol(t); int ans = 0; rep(i, n) { if (rolling_hash[i].get(0, m) == rol.get(0, m)) ans++; } cout << ans << endl; } } return 0; }