其实直接离散化就好啊,为什么会在hash的例题里面,离散化之后two-pointer就可以了。估计是搞多个模数hash可以做到吧,不过这样空间会比较炸

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int N = 1e6 + 10;

bool vis[N];
int n, a[N], b[N], ans, tot, l, r;

int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) scanf("%d", &a[i]), b[i] = a[i];
    sort(b + 1, b + n + 1);
    for(int i = 1; i <= n; ++i) a[i] = lower_bound(b + 1, b + n + 1, a[i]) - b;
    for(l = 1, r = 1; r <= n; ++r) {
        if(!vis[a[r]]) ans = max(ans, ++tot);
        else {
            while(a[l] != a[r]) vis[a[l++]] = 0;
            tot = r - l;
        }
        vis[a[r]] = 1;
    }
    printf("%d\n", ans);
}