LOADING

加载过慢请开启缓存,浏览器默认开启

daily 2

2023/8/14 daily

CF 1209G1

#define int ll
void solve() {
  int n, k;
  cin >> n >> k;
  ll ans = 0;
  vector<int> a(n + 5);
  map<int, int> cnt;
  map<int, int> pos;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i]; 
    cnt[a[i]]++;
    pos[a[i]] = i;
  }
  for (int l = 1, r = pos[a[l]]; l <= n; l = r + 1, r = pos[a[l]]) {
    int m = 0;
    for (int i = l; i <= r; r = max(r, pos[a[i]]), ++i) {
      m = max(m, cnt[a[i]]);
    }
    ans = r - l + 1 - m;
  }
  cout << ans << '\n';
  return ;
}

CF 1210C