fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. int n,k ; cin>>n>>k;
  7. vector<int>arr(n);
  8. for(int i = 0 ; i<n;i++){
  9. cin>>arr[i];
  10. }
  11. unordered_set<int>hash;
  12. bool ans = false;
  13. for(int i = 0 ; i < n;i++){
  14. if(hash.find(arr[i])!=hash.end()){
  15. ans = true;
  16. break;
  17. }
  18. hash.insert(arr[i]);
  19. if(i>k){
  20. hash.erase(arr[i-k]);
  21. }
  22. }
  23. cout<<ans;
  24. // your code goes here
  25. return 0;
  26. }
Success #stdin #stdout 0.01s 5308KB
stdin
9 3 
5 6 4 3 5 3 2 6 4
stdout
1