最长连续不重复子序列

发布于 2022-07-28  5 次阅读


#include <bits/stdc++.h>

using namespace std;
const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 998244353;
int n, a[N], ans, b[N];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", a + i);
    for (int i = 1, j = 1; i <= n; ++i) {
        b[a[i]]++;
        while (j <= i && b[a[i]] > 1)b[a[j]]--, j++;
        ans = max(ans, i - j + 1);
    }
    printf("%d", ans);
    return 0;
}