fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int n,cc,dm;
  4. deque<int>p;
  5. map<int,bool>m;
  6. signed main()
  7. {
  8. cin>>n;
  9. int a[n+1];
  10. for (int i=1;i<=n;i++)
  11. {
  12. cin>>a[i];
  13. m[a[i]]=false;
  14. }
  15. int res=0;
  16. for (int i=1;i<=n;i++)
  17. {
  18. if (m[a[i]]==false)
  19. {
  20. p.push_front(i);
  21. m[a[i]]=true;
  22. }
  23. else if (m[a[i]]==true)
  24. {
  25. while (!p.empty()&&a[p.back()]!=a[i])
  26. {
  27. p.pop_back();
  28. }
  29. if (!p.empty()) p.pop_back();
  30. p.push_front(i);
  31. }
  32. cc=p.size();
  33. res=max(res,cc);
  34. }
  35. cout<<res;
  36. }
  37.  
Success #stdin #stdout 0.01s 5308KB
stdin
Standard input is empty
stdout
Standard output is empty