找最长的,没有相同元素的区间
双指针
#include <iostream> #include <set> using namespace std; const int N=1e6+2; int n,a[N]; void solve(){ int x=1,y=1,ans=0; set<int> st; while(y<=n){ while(y<=n&&!st.count(a[y])) st.insert(a[y]),y++; ans=max(ans,y-x); st.erase(a[x]),x++; } cout<<ans<<endl; } signed main(){ int cas; cin>>cas; while(cas--){ cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; solve(); } }
标签:Unique,Snowflakes,int,cas,while,uva11572,include From: https://www.cnblogs.com/towboa/p/17324349.html