結果
問題 | No.2761 Substitute and Search |
ユーザー | Taiki0715 |
提出日時 | 2024-05-17 21:45:43 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,806 ms / 4,000 ms |
コード長 | 5,773 bytes |
コンパイル時間 | 5,831 ms |
コンパイル使用メモリ | 320,184 KB |
実行使用メモリ | 71,040 KB |
最終ジャッジ日時 | 2024-12-20 13:30:14 |
合計ジャッジ時間 | 18,126 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 2 ms
6,820 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | AC | 1,231 ms
70,912 KB |
testcase_05 | AC | 1,806 ms
70,656 KB |
testcase_06 | AC | 238 ms
70,656 KB |
testcase_07 | AC | 1,346 ms
70,912 KB |
testcase_08 | AC | 230 ms
70,656 KB |
testcase_09 | AC | 1,343 ms
71,040 KB |
testcase_10 | AC | 229 ms
70,656 KB |
testcase_11 | AC | 1,336 ms
70,784 KB |
testcase_12 | AC | 811 ms
70,912 KB |
testcase_13 | AC | 795 ms
70,784 KB |
testcase_14 | AC | 806 ms
70,784 KB |
testcase_15 | AC | 815 ms
70,784 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; template<int mod>istream &operator>>(istream &is,static_modint<mod> &a){long long b;is>>b;a=b;return is;} istream &operator>>(istream &is,modint &a){long long b;cin>>b;a=b;return is;} #endif #ifdef LOCAL #include "debug.h" #else #define debug(...) static_cast<void>(0) #define debugg(...) static_cast<void>(0) #define esper(...) static_cast<void>(0) template<typename T1,typename T2>ostream &operator<<(ostream &os,const pair<T1,T2>&p){os<<p.first<<' '<<p.second;return os;} #endif using ll=long long; using ull=unsigned long long; using P=pair<ll,ll>; template<typename T>using minque=priority_queue<T,vector<T>,greater<T>>; template<typename T>bool chmax(T &a,const T &b){return (a<b?(a=b,true):false);} template<typename T>bool chmin(T &a,const T &b){return (a>b?(a=b,true):false);} template<typename T1,typename T2>istream &operator>>(istream &is,pair<T1,T2>&p){is>>p.first>>p.second;return is;} template<typename T>istream &operator>>(istream &is,vector<T> &a){for(auto &i:a)is>>i;return is;} template<typename T1,typename T2>void operator++(pair<T1,T2>&a,int n){a.first++,a.second++;} template<typename T1,typename T2>void operator--(pair<T1,T2>&a,int n){a.first--,a.second--;} template<typename T>void operator++(vector<T>&a,int n){for(auto &i:a)i++;} template<typename T>void operator--(vector<T>&a,int n){for(auto &i:a)i--;} #define reps(i,a,n) for(int i=(a);i<(n);i++) #define rep(i,n) reps(i,0,n) #define all(x) x.begin(),x.end() #define pcnt(x) __builtin_popcountll(x) #define fin(x) return cout<<x<<'\n',static_cast<void>(0) ll myceil(ll a,ll b){return (a+b-1)/b;} template<typename T,size_t n,size_t id=0> auto vec(const int (&d)[n],const T &init=T()){ if constexpr (id<n)return vector(d[id],vec<T,n,id+1>(d,init)); else return init; } void SOLVE(); int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout<<fixed<<setprecision(16); #ifdef LOCAL clock_t start=clock(); #endif int testcase=1; //cin>>testcase; for(int i=0;i<testcase;i++){ SOLVE(); } #ifdef LOCAL cerr<<"time:"; cerr<<(clock()-start)/1000; cerr<<"ms\n"; #endif } namespace RollingHashInfo{ constexpr ull MOD=(1ull<<61)-1; constexpr ull MASK31=(1ull<<31)-1; constexpr ull MASK30=(1ull<<30)-1; ull mul(ull a,ull b){ ull au=a>>31; ull ad=a&MASK31; ull bu=b>>31; ull bd=b&MASK31; ull mid=au*bd+ad*bu; ull midu=mid>>30; ull midd=mid&MASK30; return (au*bu*2+midu+(midd<<31)+ad*bd)%MOD; } ull pow61(ull a,ull p){ ull ret=1; while(p){ if(p&1)ret=mul(ret,a); a=mul(a,a); p>>=1; } return ret; } constexpr ull MAX=100; static ull primitive_root(){ random_device rng; ull k=rng(); while(true){ if(gcd(k,MOD-1)!=1){ ull now=pow61(37,k); if(now>MAX)return now; } k=rng(); } return 0; } static ull base=primitive_root(); vector<ull>power{1}; void build(int n){ if(power.size()>=n+1)return; int pre=power.size(); power.resize(n+1); for(int i=pre;i<=n;i++)power[i]=mul(power[i-1],base); } ull connect(ull l,ull r,int len){ l=mul(l,power[len]); l+=r; if(l>=MOD)l-=MOD; return l; } } struct DynamicRollingHash{ private: vector<ull>seg; int log; int sz; int n; public: DynamicRollingHash(const string &s):n(s.size()){ log=0; while((1<<log)<n)log++; sz=1<<log; seg.resize(sz*2); RollingHashInfo::build(sz); rep(i,n)seg[i+sz]=ull(s[i]); for(int i=sz-1;i>=1;i--){ seg[i]=RollingHashInfo::mul(seg[i*2],RollingHashInfo::power[1<<(__builtin_clz(i)+log-32)])+seg[i*2+1]; if(seg[i]>=RollingHashInfo::MOD)seg[i]-=RollingHashInfo::MOD; } } ull get(int l,int r)const{ assert(0<=l&&l<=r&&r<=n); l+=sz,r+=sz; ull left=0,right=0; int rsize=0; while(l<r){ if(l&1){ left=RollingHashInfo::mul(left,RollingHashInfo::power[1<<(__builtin_clz(l)+log-31)])+seg[l]; l++; if(left>=RollingHashInfo::MOD)left-=RollingHashInfo::MOD; } if(r&1){ r--; right=RollingHashInfo::mul(seg[r],RollingHashInfo::power[rsize])+right; if(right>=RollingHashInfo::MOD)right-=RollingHashInfo::MOD; rsize+=1<<(__builtin_clz(r)+log-31); } l>>=1,r>>=1; } left=RollingHashInfo::mul(left,RollingHashInfo::power[rsize])+right; return left>=RollingHashInfo::MOD?left-RollingHashInfo::MOD:left; } void set(int i,char c){ assert(0<=i&&i<n); i+=sz; seg[i]=ull(c); i>>=1; while(i){ seg[i]=RollingHashInfo::mul(seg[i*2],RollingHashInfo::power[1<<(__builtin_clz(i)+log-32)])+seg[i*2+1]; if(seg[i]>=RollingHashInfo::MOD)seg[i]-=RollingHashInfo::MOD; i>>=1; } } }; namespace RollingHashInfo{ int lcp(const DynamicRollingHash &rh1,int l1,int r1,const DynamicRollingHash &rh2,int l2,int r2){ int len=min(r1-l1,r2-l2); int low=0,high=len+1; while(high-low>1){ int mid=(low+high)/2; if(rh1.get(l1,l1+mid)==rh2.get(l2,l2+mid))low=mid; else high=mid; } return low; } } void SOLVE(){ int n,l,q; cin>>n>>l>>q; vector<DynamicRollingHash>rs(n,DynamicRollingHash("")); vector<string>s(n); rep(i,n){ cin>>s[i]; rs[i]=DynamicRollingHash(s[i]); } 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; rs[i].set(k,d); } } else{ string t; cin>>t; DynamicRollingHash rt(t); ull g=rt.get(0,t.size()); int ans=0; rep(i,n)ans+=rs[i].get(0,t.size())==g; cout<<ans<<endl; } } }