LOADING

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

daily 1

2023/7/29

CF 1335E2

void solve() {
  int n, ans = 0;
  cin >> n;
  vector<int> pos[MAXN];
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= 200; ++j) {
        cnt[i][j] = 0;
    }
  }
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    memcpy(cnt[i], cnt[i - 1], sizeof(cnt[i - 1]));
    cnt[i][a[i]]++;
    pos[a[i]].push_back(i);
  }
  for (int i = 1; i <= 200; ++i) {
    int sz = pos[i].size();
    ans = max(ans, sz);
    for (int j = 0; j < sz / 2; ++j) {
      int l = pos[i][j], r = pos[i][sz - j - 1] - 1;
      for (int k = 1; k <= 200; ++k) {
        int mid = cnt[r][k] - cnt[l][k];
        ans = max(ans, (j + 1) * 2 + mid);
      }
    }
  }
  cout << ans << '\n';
  return;
}