結果

問題 No.3853 Unique Letters between Equal Letters
コンテスト
ユーザー Kude
提出日時 2026-12-04 22:57:55
言語 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,644 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,734 ms
コンパイル使用メモリ 358,744 KB
実行使用メモリ 9,920 KB
最終ジャッジ日時 2026-12-04 22:58:02
合計ジャッジ時間 6,837 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 2 WA * 28
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  auto f = [&](int l, int r) {
    static VI pre[10];
    rep(i, 10) pre[i].clear();
    ll res = 0;
    int lb = l;
    for (int i = l; i < r; i++) {
      int v = s[i] - '0';
      pre[v].emplace_back(i);
      if (pre[v].size() >= 2) {
        if (pre[v].size() >= 4) chmax(lb, pre[v].end()[-4] + 1);
        int p = pre[v].size() >= 3 ? pre[v].end()[-3] : pre[v].end()[-2];
        rep(w, 10) if (w != v && pre[w].size() >= 2 && pre[w].end()[-2] > p) {
          chmax(lb, p + 1);
          break;
        }
      }
      res += max(0, i - 1 - lb);
    }
    return res;
  };
  ll ans = f(0, n);
  rep(_, q) {
    int i;
    char c;
    cin >> i >> c;
    i--;
    int l = max(i - 33, 0), r = min(n, i + 33);
    ans -= f(l, r);
    s[i] = c;
    ans += f(l, r);
    cout << ans << '\n';
  }
}
0