题目大意:
给n个数, n<=100W,求一个连续子序列,这个子序列中没有重复的数,问这个子序列最长是多少?
典型的滑动窗口问题
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
const int maxn = 1000000 + 5;
int n, g[maxn];
map<int, int> v;
int main()
{
int cas;
cin>>cas;
while (cas--) {
v.clear();
cin>>n;
for (int i = 0; i < n; i++)
cin>>g[i];
int l = 0, ans = 0;
for (int r = 0; r < n; r++) {
v[g[r]]++;
while (v[g[r]] == 2) v[g[l++]]--;
ans = max(r - l + 1, ans);
}
cout<<ans<<endl;
}
return 0;
}