#include<iostream>
#include<string>
#include<cassert>
#include<algorithm>
#include<map>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<set>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<queue>
#include<unordered_map>
#include<tuple>
#include<complex>
#include<memory>
using namespace std;
int main()
{
//freopen("input.txt", "r", stdin);
int t;
scanf("%d", &t);
while (t-- > 0)
{
int n;
scanf("%d", &n);
vector<int>snowflake(n);
unordered_map<int,int>nowsnow;
for (int i = 0; i < n; ++i)
{
scanf("%d", &snowflake[i]);
}
int start = 0;
int end = 0;
int maxlength = 0;
while (end < n)
{
while (end < n && nowsnow.count(snowflake[end]) == 0)
{
nowsnow[snowflake[end]] = end;
++end;
}
maxlength = max(maxlength, end - start);
while (end<n&&nowsnow.count(snowflake[end])>0&&start<= nowsnow[snowflake[end]])nowsnow.erase(snowflake[start++]);
}
cout << maxlength << endl;
}
}
紫书 唯一的雪花 UVa11572
最新推荐文章于 2021-07-01 11:41:40 发布