結果

問題 No.2761 Substitute and Search
ユーザー wingu
提出日時 2024-09-27 20:56:19
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2,609 ms / 4,000 ms
コード長 7,145 bytes
コンパイル時間 3,085 ms
コンパイル使用メモリ 267,388 KB
実行使用メモリ 138,880 KB
最終ジャッジ日時 2024-09-27 20:56:43
合計ジャッジ時間 22,194 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#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;
mt19937_64 rnd(time(0));
static constexpr long long mod = (1LL << 61) - 1;
static const long long base = rnd() % (mod - 4) + 2;
struct RollingHash {
vector<long long> hash, power;
int n;
string s;
inline long long add(long long a, long long b) const {
if ((a += b) >= mod) a -= mod;
return a;
}
inline long long mul(long long a, long long b) const {
__int128_t x = (__int128_t)a * b;
return add(x >> 61, x & mod);
}
explicit RollingHash(const string& S) {
n = (int)S.size();
s = S;
hash.resize(n + 1, 0);
power.resize(n + 1, 1);
for (int i = 0; i < n; i++) {
hash[i + 1] = add(mul(hash[i], base), S[i]);
power[i + 1] = mul(power[i], base);
}
}
inline long long get(int l, int r) const {
return add(hash[r], mod - mul(hash[l], power[r - l]));
}
inline long long get() const {
return hash.back();
}
inline long long connect(long long hash1, long long hash2, int hash2_len) const {
return add(mul(hash1, power[hash2_len]), hash2);
}
inline int lcp(int a, int b) const {
int len = min((int)hash.size() - a, (int)hash.size() - b);
int left = 0, right = len;
while (right - left > 1) {
int mid = (left + right) / 2;
if (get(a, a + mid) != get(b, b + mid)) {
right = mid;
} else {
left = mid;
}
}
return left;
}
inline int lcp(const RollingHash& T, int a, int b) const {
int len = min((int)hash.size() - a, (int)T.hash.size() - b);
int left = 0, right = len;
while (right - left > 1) {
int mid = (left + right) / 2;
if (get(a, a + mid) != T.get(b, b + mid)) {
right = mid;
} else {
left = mid;
}
}
return left;
}
};
#include <atcoder/segtree>
// mt19937_64 rnd(time(0));
// 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();
RollingHash rol(t);
int ans = 0;
rep(i, n) {
if (rolling_hash[i].get(0, m) == rol.get()) ans++;
}
cout << ans << endl;
}
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0