题意:
找到最大连续有重复数字的子段
#include <iostream>
#include <stdio.h>
#include <map>
#include <cstring>
#include <queue>
using namespace std;
const int maxn=300005;
int a[maxn];
int l[maxn];
int r[maxn];
int now[maxn];
int main()
{
map<int,int>mp;
int n;
int cnt=0;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
if(mp.count(a[i])==0)
{
mp[a[i]]=++cnt;
}
}
int ans=0;
queue<int>q;
int st=1;
for(int i=1;i<=n;i++)
{
int pos=mp[a[i]];
if(now[pos]==0)
{
now[pos]=i;
q.push(pos);
}
else
{
l[++ans]=st;
r[ans]=i;
st=i+1;
while(!q.empty())
{
int t=q.front();
now[t]=0;
q.pop();
}
}
}
if(ans==0)
{
printf("-1\n");
return 0;
}
r[ans]=n;
printf("%d\n",ans);
for(int i=1;i<=ans;i++)
{
printf("%d %d\n",l[i],r[i]);
}
return 0;
}