Advertisement
a53

sum_unice

a53
Nov 3rd, 2020
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int a[123459],n,k;
  4. unordered_map<int,int> M;
  5.  
  6. int main()
  7. {
  8. int total,nrD;
  9. cin>>n>>k;
  10. for(int i=0;i<n;++i)
  11. cin>>a[i];
  12. nrD=0;
  13. for(int i=0;i<k;++i)
  14. {
  15. ++M[a[i]];
  16. if(M[a[i]]==1)
  17. ++nrD;
  18. if(M[a[i]]==2)
  19. --nrD;
  20. }
  21. total=nrD;
  22. for(int i=k;i<n;++i)
  23. {
  24. --M[a[i-k]];
  25. if(M[a[i-k]]==0)
  26. --nrD;
  27. if(M[a[i-k]]==1)
  28. ++nrD;
  29. ++M[a[i]];
  30. if(M[a[i]]==1)
  31. ++nrD;
  32. if(M[a[i]]==2)
  33. --nrD;
  34. total+=nrD;
  35. }
  36. cout<<total;
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement