AcWing 799. 最长连续不重复子序列
原题链接
简单
作者:
小露狂粉
,
2023-11-16 19:12:04
,
所有人可见
,
阅读 48
队列打卡
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 100010;
int p[N],temp[N],q[N];
int head=0,end1=-1;
int main()
{
int n,res=0;
cin>>n;
memset(temp, 0, sizeof temp);
for(int i=0;i<n;i++) cin>>p[i];
for(int i=0;i<n;i++){
if(head>end1){
q[++end1]=p[i];
temp[p[i]]++;
}
else{
temp[p[i]]++;
if(temp[p[i]]>1){
res=max(res,end1-head+1);
while(q[head]!=p[i])
{
temp[q[head]]=0;
head++;
}
head++;
q[++end1]=p[i];
}
else{
q[++end1]=p[i];
}
}
}
cout<<max(res,end1-head+1);
return 0;
}