結果

問題 No.3853 Unique Letters between Equal Letters
コンテスト
ユーザー cho435
提出日時 2026-12-05 08:05:54
言語 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  
実行時間 2,730 ms / 3,000 ms
+ 350µs
コード長 1,529 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,832 ms
コンパイル使用メモリ 344,000 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2026-12-05 08:06:45
合計ジャッジ時間 50,436 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_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<set<int>> idx(10);
	rep(i, 0, n) idx[s[i] - '0'].insert(i);
	vector<int> nx(n, 0);
	auto rebuild = [&](int i) {
		if(nx[i] - i >= 3) ans -= nx[i] - i - 2;
		vector<set<int>> idx(10);
		int j = i;
		while(j < n) {
			int c = s[j] - '0';
			int mn = 1e9;
			if(!idx[c].empty()) mn = *idx[c].begin();
			int f = 0;
			rep(k, 0, 10) {
				auto itr = idx[k].upper_bound(mn);
				if(itr == idx[k].end()) continue;
				itr++;
				if(itr != idx[k].end()) f = 1;
			}
			if(f) break;
			idx[c].insert(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