結果
| 問題 |
No.3239 Omnibus
|
| コンテスト | |
| ユーザー |
Iroha_3856
|
| 提出日時 | 2025-08-15 23:12:37 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,846 bytes |
| コンパイル時間 | 5,679 ms |
| コンパイル使用メモリ | 335,152 KB |
| 実行使用メモリ | 58,852 KB |
| 最終ジャッジ日時 | 2025-08-15 23:12:52 |
| 合計ジャッジ時間 | 9,252 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 3 WA * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using mint = atcoder::modint998244353;
#define rep(i, l, r) for (int i = (int)(l); i<(int)(r); i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define siz(x) (int)(x).size()
template<class T> bool chmin(T& a, T b) { if (a > b) {a = b; return true;} return false; }
template<class T> bool chmax(T& a, T b) { if (a < b) {a = b; return true;} return false; }
const int inf = 1e9;
const ll INF = 4e18;
template<class T> using pq = priority_queue<T, vector<T>, less<T>>;
template<class T> using spq = priority_queue<T, vector<T>, greater<T>>;
vector<int> di = {0, 0, 1, -1};
vector<int> dj = {1, -1, 0, 0};
struct IoSetup {
IoSetup() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
cerr << fixed << setprecision(15);
}
} iosetup;
struct Edge {
int to; ll cost;
};
void solve() {
int N, Q; cin >> N >> Q;
//O(NQ)許してください...
string S; cin >> S;
int B = 500;
int cnt[(N-1)/B+1][26][26][26];
int sum[(N-1)/B+1][26][26][26];
rep(i, 0, Q) {
int q; cin >> q;
if (q == 1) {
int k; char x; cin >> k >> x;
k--;
rep(i, k-2, k+1) {
cnt[i/B][S[i]-'a'][S[i+1]-'a'][S[i+2]-'a']--;
sum[i/B][S[i]-'a'][S[i+1]-'a'][S[i+2]-'a']-=i;
}
S[k] = x;
rep(i, k-2, k+1) {
cnt[i/B][S[i]-'a'][S[i+1]-'a'][S[i+2]-'a']++;
sum[i/B][S[i]-'a'][S[i+1]-'a'][S[i+2]-'a']+=i;
}
}
else {
int l, r; cin >> l >> r;
string a; cin >> a;
l--;
r-=2;
if (r - l <= 1000) {
ll ans = 0;
rep(k, l, r) {
if (S[k] == a[0] and S[k+1] == a[1] and S[k+2] == a[2]) ans += k - l + 1;
}
cout << ans << endl;
continue;
}
//[l, r) でクエリに答える
int L = (l + B - 1)/B;
int R = r / B;
ll ans = 0;
rep(i, L, R) {
ans += sum[i][a[0]-'a'][a[1]-'a'][a[2]-'a'] - cnt[i][a[0]-'a'][a[1]-'a'][a[2]-'a'] * (l - 1);
}
rep(k, l, L*B) {
if (S[k] == a[0] and S[k+1] == a[1] and S[k+2] == a[2]) ans += k - (l - 1);
}
rep(k, R*B, r) {
if (S[k] == a[0] and S[k+1] == a[1] and S[k+2] == a[2]) ans += k - (l - 1);
}
}
}
}
int main() {
int T = 1;
// cin >> T;
while(T--) {
solve();
}
}
Iroha_3856