#include<bits/stdc++.h>
using namespace std;
int a[500010];
int main()
{
ios::sync_with_stdio(false);
int n,k,x,c=0;
cin>>n>>k;
set<int> mp;
map<int,int> s;
int f=1;
int l=1,r=1;
for(int i=1;i<=n;i++)
{
cin>>x;
mp.insert(x);
if(s[x]==0) c++;
s[x]++;
a[i]=x;
while(c>k)
{
s[a[f]]--;
if(s[a[f]]==0) c--;
f++;
}
if(i-f>(r-l))
{
r = i;
l = f;
}
}
cout<<l<<" "<<r<<endl;
return 0;
}
双指针(尺取)
最新推荐文章于 2024-07-19 15:39:46 发布