该代码 WA 8 个点
#include<bits/stdc++.h>
using namespace std;
long long n,a[100005],b[100005],ans,x,y,from=1,to=1,f,t;
int main() {
ios::sync_with_stdio(false);
cin>>n;
for (long long i=1; i<=n; i++) {
cin>>a[i];
b[a[i]]++;
to++;
if (!(a[i]==x||y==a[i])) {
if (x==0) x=a[i];
else if (y==0) y=a[i];
else {
while (b[x]!=0&&b[y]!=0) {
b[a[from]]--;
from++;
}
if (b[x]==0) x=a[i];
else y=a[i];
}
}
if (to-from>ans) {
f=from;
t=to;
ans=to-from;
}
}
cout<<ans<<"\n";
for (int i=f; i<t; i++) {
cout<<a[i]<<" ";
}
return 0;
}