結果

問題 No.3853 Unique Letters between Equal Letters
コンテスト
ユーザー GOTKAKO
提出日時 2026-12-04 22:18:56
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 266 ms / 3,000 ms
+ 914µs
コード長 1,095 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,438 ms
コンパイル使用メモリ 216,948 KB
実行使用メモリ 9,904 KB
最終ジャッジ日時 2026-12-04 22:19:05
合計ジャッジ時間 8,854 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <cassert>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N,Q; cin >> N >> Q;
    string s; cin >> s;
    int answer = 0;

    vector<int> C(N);
    auto f = [&](int pos) -> void {
        C.at(pos) = 0;
        int ap = 0,start = pos,ng = 0;
        vector<int> c(10);
        while(pos < N){
            int v = s.at(pos)-'0';
            if(ng&(1<<v)) return;
            for(int i=0; i<10; i++) if(ap&(1<<i)){
                if(c.at(i)&(1<<v)) ng |= 1<<i;
                c.at(i) |= 1<<v;
            }
            ap |= 1<<v;
            C.at(start)++,pos++;
        }
    };    
    for(int i=0; i<N; i++) f(i),answer += C.at(i);
    while(Q--){
        int pos; char c; cin >> pos >> c,pos--;
        for(int i=pos; i>=pos-30; i--){
            if(i < 0) break;
            answer -= C.at(i);
        }    
        s.at(pos) = c;
        for(int i=pos; i>=pos-30; i--){
            if(i < 0) break;
            f(i),answer += C.at(i);
        }    
        cout << answer-N-(N-1) << "\n";
    }

}
0