fork(2) 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. main()
  5. {
  6. io
  7. int n;
  8. cin>>n;
  9. unordered_map<int,int>lastind;
  10. int a[n+1];
  11. for(int i=1;i<=n;i++)
  12. {
  13. cin>>a[i];
  14. }
  15. int i=1,ans=0;
  16. for(int j=1;j<=n;j++)
  17. {
  18. i=max(i,lastind[a[j]]+1);
  19. ans=max(ans,j-i+1);
  20. lastind[a[j]]=j;
  21. }
  22. cout<<ans<<endl;
  23. }
  24.  
Success #stdin #stdout 0s 4532KB
stdin
Standard input is empty
stdout
12