【題目敘述】https://zerojudge.tw/ShowProblem?problemid=d194
#include <iostream>
#include <set>
#include <queue>
using namespace std;
int t, n, a, ans;
set <int> st;
queue <int> q;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> t;
while (t--){
cin >> n;
ans = 0;
st.clear();
while (n--){
cin >> a;
if (st.count(a)){
ans = max(ans, (int)st.size());
while (q.front()!=a){
st.erase(q.front());
q.pop();
}
q.pop();
}
st.insert(a);
q.push(a);
}
ans = max(ans, (int)st.size());
while (!q.empty()) q.pop();
cout << ans << "\n";
}
}