結果
| 問題 |
No.2992 Range ABCD String Query
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-12-18 11:45:34 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 541 ms / 6,000 ms |
| コード長 | 1,556 bytes |
| コンパイル時間 | 3,876 ms |
| コンパイル使用メモリ | 253,400 KB |
| 実行使用メモリ | 48,828 KB |
| 最終ジャッジ日時 | 2024-12-18 11:45:57 |
| 合計ジャッジ時間 | 19,970 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 41 |
ソースコード
#ifndef LOCAL
#include <bits/stdc++.h>
using namespace std;
#define debug(...) (void(0))
#else
#include "algo/debug.h"
#endif
#include <atcoder/segtree>
constexpr int inf = 1e9;
constexpr int M = 4;
using S = array<array<int, M>, M>;
S e() {
return S{};
}
S op(S a, S b) {
S res;
for(int i = 0; i < M; i++) for(int j = 0; j < M; j++) res[i][j] = inf;
for (int i = 0; i < M; i++) {
for (int j = i; j < M; j++) {
for (int k = i; k <= j; k++) {
res[i][j] = min(res[i][j], a[i][k] + b[k][j]);
}
}
}
return res;
}
S mk(int t) {
S res = e();
for(int i = 0; i < M; i++) {
for(int j = i; j < M; j++) {
if(i <= t && t <= j) res[i][j] = 0;
else res[i][j] = 1;
}
}
return res;
}
void solve() {
int N, Q; cin >> N >> Q;
string T; cin >> T;
atcoder::segtree<S, op, e> seg(N);
for(int i = 0; i < N; i++) seg.set(i, mk(T[i] - 'A'));
while(Q--) {
int t; cin >> t;
if(t == 1) {
int p; char c; cin >> p >> c;
seg.set(--p, mk(c - 'A'));
} else {
int l, r; cin >> l >> r;
l--;
S res = seg.prod(l, r);
int ans = inf;
for(int i = 0; i < M; i++) for(int j = i; j < M; j++) ans = min(ans, res[i][j]);
cout << ans << '\n';
}
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int tt = 1;
// std::cin >> tt;
while (tt--) {
solve();
}
}