結果

問題 No.3853 Unique Letters between Equal Letters
コンテスト
ユーザー Iroha_3856
提出日時 2026-12-04 22:31:16
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,893 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,009 ms
コンパイル使用メモリ 362,332 KB
実行使用メモリ 20,004 KB
最終ジャッジ日時 2026-12-04 22:31:33
合計ジャッジ時間 17,192 ms
ジャッジサーバーID
(参考情報)
judge6_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 25 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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 - 20); l <= i; l++) update(l);
        cout << sum - N - N - (N - 1) << "\n";
    }
}
0