Untitled
unknown
plain_text
2 years ago
1.2 kB
11
Indexable
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl "\n"
const double PI = 3.14159265358979;
const ll INF = 1e18 + 7;
const ll MOD = 1e9 + 7;
const ll nax = 1000006;
const int LOG = 25;
void solve() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int tail = 0, head = -1, ans = 0;
set<int> currentWidowElements;
while(tail < n) {
while(head + 1 < n && currentWidowElements.find(a[head + 1]) == currentWidowElements.end()) {
head++;
currentWidowElements.insert(a[head]);
}
if (head - tail + 1 > 0) {
ans = max(ans, head - tail + 1);
}
if (tail <= head) {
auto it = currentWidowElements.find(a[tail]);
if (it != currentWidowElements.end()) {
currentWidowElements.erase(it);
}
tail++;
} else {
tail++;
head = tail - 1;
}
}
cout << ans << endl;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t; cin >> t; while(t--)
solve();
return 0;
}
Editor is loading...
Leave a Comment