AcWing 799. 最长连续不重复子序列
原题链接
简单
作者:
m_math
,
2024-04-08 16:18:24
,
所有人可见
,
阅读 7
STL大法
#include <iostream>
#include <algorithm>
#include <unordered_set>
using namespace std;
const int N = 100010;
int n;
int a[N];
int res;
unordered_multiset<int> s;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> n;
for(int i = 1;i <= n;i++)
cin >> a[i];
for(int i = 1,j = 1;j <= n;j++)
{
while(i <= j && s.find(a[j]) != s.end()) s.erase(s.find(a[i++]));
s.insert(a[j]);
res = max(res,j - i + 1);
}
cout << res << endl;
return 0;
}