Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ======================
- [ ___T_ ]
- [ | 6=6 | =>HI :-)]
- [ |__o__| ]
- [ >===]__o[===< ]
- [ [o__] ]
- [ .". ]
- [ |_| ]
- [ ]
- ======================
- */
- #include<bits/stdc++.h>
- using namespace std;
- using lli = int64_t;
- int main() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int T = 1;
- for(int t = 1; t <= T; t++) {
- int n,k;
- cin >> n >> k;
- int input[n + 1];
- for(int i = 1; i <= n; i++){
- cin >> input[i];
- }
- map<int,int> count;
- set<int> distincts;
- int l = 1;
- int range_l = 1,range_r = n;
- for(int i = 1; i <= n; i++){
- count[input[i]] += 1;
- distincts.insert(input[i]);
- if((int) distincts.size() >= k){
- if(range_r - range_l > i - l){
- range_l = l,range_r = i;
- }
- }
- while((int) distincts.size() == k){
- if(count[input[l]] > 1){
- count[input[l]] -= 1;
- }else{
- count[input[l]] = 0;
- distincts.erase(input[l]);
- }
- l += 1;
- if((int) distincts.size() >= k){
- if(range_r - range_l > i - l){
- range_l = l,range_r = i;
- }
- }
- }
- if((int) distincts.size() >= k){
- if(range_r - range_l > i - l){
- range_l = l,range_r = i;
- }
- }
- }
- cout << range_l << " " << range_r << "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement