結果

問題 No.3853 Unique Letters between Equal Letters
コンテスト
ユーザー cho435
提出日時 2026-12-05 08:09:02
言語 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
結果
AC  
実行時間 1,968 ms / 3,000 ms
+ 923µs
コード長 1,402 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,686 ms
コンパイル使用メモリ 340,548 KB
実行使用メモリ 9,828 KB
最終ジャッジ日時 2026-12-05 08:09:41
合計ジャッジ時間 38,764 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep4(i,a,b,c) for(ll i= (ll)a; i<(ll)(b); i+=(c))
#define rep3(i,a,b) rep4(i,a,b,1)
#define rep2(i,a) rep3(i,0,a)
#define rep1(a) rep2(aaaaa,a)
#define ov4(a,b,c,d,name,...) name
#define rep(...) ov4(__VA_ARGS__, rep4, rep3, rep2, rep1) (__VA_ARGS__)
#define per(i, a, b) for(ll i=(a)-1; i>=(ll)(b); i--)
#define all(a) begin(a), end(a)

struct _ {
	_() {
		cin.tie(0)->sync_with_stdio(0), cout.tie(0);
	}
} __;

template<class T> bool chmax(T& a, T b) {
	return a < b ? a = b, 1 : 0;
}
template<class T> bool chmin(T& a, T b) {
	return a > b ? a = b, 1 : 0;
}

void solve() {
	int n, q;
	cin >> n >> q;
	string s;
	cin >> s;
	ll ans = 0;
	vector<int> nx(n, 0);
	auto rebuild = [&](int i) {
		if(nx[i] - i >= 3) ans -= nx[i] - i - 2;
		vector<vector<int>> idx(10);
		int j = i;
		while(j < n) {
			int c = s[j] - '0';
			int mn = 1e9;
			if(!idx[c].empty()) mn = idx[c][0];
			int f = 0;
			rep(k, 0, 10) {
				if(idx[k].end() - upper_bound(all(idx[k]), mn) >= 2) f = 1;
			}
			if(f) break;
			idx[c].push_back(j);
			j++;
		}
		nx[i] = j;
		if(nx[i] - i >= 3) ans += nx[i] - i - 2;
	};
	rep(i, 0, n) rebuild(i);
	while(q--) {
		int i;
		char c;
		cin >> i >> c;
		i--;
		s[i] = c;
		rep(j, max(0, i - 30), min(n, i + 30)) rebuild(j);
		cout << ans << '\n';
	}
}

int main() {
	int t = 1;
	// cin >> t;
	while(t--) solve();
}
0