結果
問題 |
No.3239 Omnibus
|
ユーザー |
![]() |
提出日時 | 2025-08-16 18:19:16 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,553 bytes |
コンパイル時間 | 4,593 ms |
コンパイル使用メモリ | 269,428 KB |
実行使用メモリ | 298,404 KB |
最終ジャッジ日時 | 2025-08-16 18:22:48 |
合計ジャッジ時間 | 104,139 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 18 TLE * 12 -- * 3 |
ソースコード
/** author: shobonvip created: 2025.08.16 18:04:39 **/ #include<bits/stdc++.h> using namespace std; //* ATCODER #include<atcoder/all> using namespace atcoder; typedef modint998244353 mint; //*/ /* 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--) #define all(v) v.begin(), v.end() 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; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n,q;cin>>n>>q; string s;cin>>s; const int sz=1<<18; auto get=[&](unordered_map<int,ll>&mp, int i) -> ll { if(mp.find(i)==mp.end())return 0LL; return mp[i]; }; auto upd=[&](unordered_map<int,ll>&mp, int i, ll j) -> void { i+=sz; mp[i]=j; if(mp[i]==0LL)mp.erase(i); i>>=1; while(i>0){ mp[i]=get(mp,2*i)+get(mp,2*i+1); if(mp[i]==0LL)mp.erase(i); i>>=1; } return; }; auto prod=[&](unordered_map<int,ll>&mp, int l, int r) -> ll { l+=sz; r+=sz; ll ret=0; while(l<r){ if(l&1){ ret+=get(mp,l); l++; } if(r&1){ r--; ret+=get(mp,r); } l>>=1; r>>=1; } return ret; }; map<string,unordered_map<int,ll>> mp0; map<string,unordered_map<int,ll>> mp1; rep(i,2,n){ upd(mp0[s.substr(i-2,3)],i,1LL); upd(mp1[s.substr(i-2,3)],i,(ll)i); } while(q--){ int t;cin>>t; if(t==1){ int k;char c; cin>>k>>c; k--; rep(j,max(2,k),min(k+3,n)){ upd(mp0[s.substr(j-2,3)],j,0LL); upd(mp1[s.substr(j-2,3)],j,0LL); } s[k]=c; rep(j,max(2,k),min(k+3,n)){ upd(mp0[s.substr(j-2,3)],j,1LL); upd(mp1[s.substr(j-2,3)],j,(ll)j); } }else{ int l,r; cin>>l>>r; l--; string a;cin>>a; if(r-l<=2){ cout<<0<<'\n'; continue; } ll v1=prod(mp1[a],l+2,r); ll v0=prod(mp0[a],l+2,r); ll ans=v1-(l+1)*v0; cout<<ans<<'\n'; } } }