結果
問題 |
No.3239 Omnibus
|
ユーザー |
![]() |
提出日時 | 2025-08-15 22:10:49 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,603 bytes |
コンパイル時間 | 4,158 ms |
コンパイル使用メモリ | 259,872 KB |
実行使用メモリ | 372,076 KB |
最終ジャッジ日時 | 2025-08-15 22:11:37 |
合計ジャッジ時間 | 19,459 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 4 TLE * 1 -- * 28 |
ソースコード
#include <stdio.h> #include <atcoder/all> #include <bits/stdc++.h> using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000005 #define Inf64 1000000000000000001LL string s; map<short,long long> mc[1<<19],mr[1<<19]; void dfs(short s,int pos,int oripos, int add){ if(pos==0)return; mc[pos][s] += add; mr[pos][s] += add * oripos; if(add < 0){ if(mc[pos][s]==0){ mc[pos].erase(s); mr[pos].erase(s); } } dfs(s,pos/2,oripos,add); } void deal(int pos,int add){ if(pos < 2)return; if(pos >= s.size())return; string t = s.substr(pos-2,3); short cur = 0; rep(i,3){ cur *= 26; cur += t[i] - 'a'; } dfs(cur, pos + (1<<18),pos, add); } int main(){ int n,q; cin>>n>>q; cin>>s; rep(i,n){ deal(i,1); } rep(_,q){ int t; cin>>t; if(t==1){ int i; char c; cin>>i>>c; i--; rep(j,3){ deal(i+j,-1); } s[i] = c; rep(j,3){ deal(i+j,1); } } else{ int l,r; cin>>l>>r; l--; string a; cin>>a; short ta = 0; rep(i,3){ ta *= 26; ta += a[i] - 'a'; } if(r-l < 3){ cout<<0<<endl; continue; } l += 2; long long tl = l,tr = r; l += 1<<18; r += 1<<18; long long ans = 0,c = 0; while(true){ if(l&1){ if(mc[l].count(ta)){ c += mc[l][ta]; ans += mr[l][ta]; } l++; } if(r&1){ r--; if(mc[r].count(ta)){ c += mc[r][ta]; ans += mr[r][ta]; } } if(l>=r)break; l >>=1; r >>= 1; } ans -= (tl-1) * c; cout<<ans<<endl; } } }