1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| #include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 50; unordered_map<int, int> vis; int t, n, a[maxn];
void f() { vis.clear(); int l = 1, r = 1, ans = 0; cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; while (l <= r && r <= n) { while (r <= n && !vis[a[r]]) ++vis[a[r++]]; ans = max(ans, r - l); while (a[l] != a[r]) --vis[a[l++]]; --vis[a[l++]]; } cout << ans << endl; }
int main() { cin >> t; while (t--) f(); return 0; }
|