結果
問題 |
No.3239 Omnibus
|
ユーザー |
![]() |
提出日時 | 2025-08-15 22:48:23 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 8,227 ms / 10,000 ms |
コード長 | 2,466 bytes |
コンパイル時間 | 3,402 ms |
コンパイル使用メモリ | 305,972 KB |
実行使用メモリ | 217,992 KB |
最終ジャッジ日時 | 2025-08-15 22:51:36 |
合計ジャッジ時間 | 148,211 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 33 |
ソースコード
#include<bits/stdc++.h> namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include<atcoder/all> #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair<int,int>; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<ll>; using VVL = vector<VL>; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; string s; cin >> s; auto f = [&](int i) { assert(0 <= i && i + 3 <= n); int v = 0; rep(j, 3) v = v * 26 + (s[i + j] - 'a'); return v; }; int k2 = bit_ceil(0U + n); struct S { int s0; ll s1; }; vector<map<int, S>> d(2 * k2); auto add = [&](int i) { int x = f(i); for (int p = i + k2; p; p >>= 1) { auto& t = d[p][x]; t.s0++; t.s1 += i; } }; auto rmv = [&](int i) { int x = f(i); for (int p = i + k2; p; p >>= 1) { auto it = d[p].find(x); if (--it->second.s0 == 0) d[p].erase(it); else it->second.s1 -= i; } }; rep(i, n - 2) add(i); while (q--) { int op; cin >> op; if (op == 1) { int k; char x; cin >> k >> x; k--; rep(j, 3) { int i = k - j; if (0 <= i && i + 3 <= n) rmv(i); } s[k] = x; rep(j, 3) { int i = k - j; if (0 <= i && i + 3 <= n) add(i); } } else { int l, r; cin >> l >> r; l--, r -= 2; const int l0 = l; int v = 0; rep(_, 3) { char c; cin >> c; v = v * 26 + (c - 'a'); } int s0 = 0; ll s1 = 0; l += k2, r += k2; while (l < r) { if (l & 1) { if (auto it = d[l].find(v); it != d[l].end()) s0 += it->second.s0, s1 += it->second.s1; l++; } if (r & 1) { r--; if (auto it = d[r].find(v); it != d[r].end()) s0 += it->second.s0, s1 += it->second.s1; } l >>= 1, r >>= 1; } ll ans = s1 - (ll)l0 * s0 + s0; cout << ans << '\n'; } } }