-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD.cpp
45 lines (40 loc) · 936 Bytes
/
D.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <bits/stdc++.h>
#define fi first
#define se second
#define DB double
#define U unsigned
#define P std::pair
#define LL long long
#define LD long double
#define pb push_back
#define MP std::make_pair
#define SZ(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const int MAXN = 5e5 + 5;
int n,a[MAXN],k;
int cnt[1000000+5],now;
inline void add(int x){
if(!cnt[x]) ++now;
++cnt[x];
}
inline void del(int x){
--cnt[x];if(!cnt[x]) --now;
}
int main(){
scanf("%d%d",&n,&k);
FOR(i,1,n) scanf("%d",a+i);
int l = 1,mx = 0,L = 1,R = 0;
FOR(r,1,n){
add(a[r]);
while(now > k) del(a[l++]);
if(R-L+1 < r-l+1){
L = l;R = r;
}
}
printf("%d %d\n",L,R);
return 0;
}