Source Code
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
int main()
{
  fastIO
  map <int,int> m;
  int n,ans=0;cin>>n;
  for(int i=1;i<n;i++)
  {
    int x;cin>>x;
    if(m[x])ans=max(ans,abs(i-m[x]+1));
    else m[x]=i;
  }
  if(n==1)ans=1;
  cout<<ans<<"\n";
}
Copy
Good Segment 3am0rab1
GNU G++17
0 ms
608 KB
Wrong Answer