結果
| 問題 | No.3853 Unique Letters between Equal Letters |
| コンテスト | |
| ユーザー |
Iroha_3856
|
| 提出日時 | 2026-12-04 22:32:13 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 545 ms / 3,000 ms |
| + 383µs | |
| コード長 | 1,892 bytes |
| 記録 | |
| コンパイル時間 | 3,914 ms |
| コンパイル使用メモリ | 362,364 KB |
| 実行使用メモリ | 19,856 KB |
| 最終ジャッジ日時 | 2026-12-04 22:32:34 |
| 合計ジャッジ時間 | 20,188 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge4_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/modint>
using mint = atcoder::modint998244353;
#include <atcoder/convolution>
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define siz(x) (int)x.size()
#define debug(x) cout << #x << " : " << endl; for (auto u : x) cout << u << " "; cout << endl
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int inf = 1e9;
const ll INF = 4e18;
int main() {
int N, Q; cin >> N >> Q;
string S; cin >> S;
int M = 30;
//21以上になったら詰むんじゃないか?
vector<vector<int>> ans(N, vector<int>(M + 1, 0));
ll sum = 0;
auto update = [&](int l) -> void {
rep(k, 0, M + 1) sum -= ans[l][k];
ans[l][0] = 1;
vector<bool> app(10, false), ok(10, true);
vector<int> seen(10, 0);
for (int r = l + 1; r <= min(N, l + M); r++) {
if (ans[l][r - l - 1] == 0) {
ans[l][r - l] = 0;
continue;
}
//面倒だなあ
int c = S[r - 1] - '0';
ans[l][r - l] = ok[c];
rep(k, 0, 10) {
if (app[k]) {
if (seen[k] >> c & 1) ok[k] = false;
else seen[k] |= (1 << c);
}
}
app[c] = true;
}
rep(k, 0, M + 1) sum += ans[l][k];
};
rep(i, 0, N) update(i);
// rep(i, 0, N) {
// rep(j, 0, M + 1) cout << ans[i][j] << " ";
// cout << endl;
// }
while(Q--) {
int i; char c; cin >> i >> c;
i--;
S[i] = c;
for (int l = max(0, i - M); l <= i; l++) update(l);
cout << sum - N - N - (N - 1) << "\n";
}
}
Iroha_3856