fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  4.  
  5. main()
  6. {
  7. io
  8. int n;
  9. cin>>n;
  10. map<int,int>lastind;
  11. int a[n+1];
  12. for(int i=1;i<=n;i++)
  13. {
  14. cin>>a[i];
  15. }
  16. int i=1,ans=0;
  17. for(int j=1;j<=n;j++)
  18. {
  19. i=max(i,lastind[a[j]]+1);
  20. ans=max(ans,j-i+1);
  21. lastind[a[j]]=j;
  22. }
  23. cout<<ans<<endl;
  24. }
Success #stdin #stdout 0s 4292KB
stdin
Standard input is empty
stdout
12