fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5. #define __luciousx__ signed main()
  6. #define fast ios_base::sync_with_stdio(false); cin.tie(nullptr);
  7.  
  8. const int maxn = 1e6 + 9;
  9. static ll arr[maxn];
  10. int n;
  11.  
  12. ll khovl(ll K)
  13. {
  14. if (K < 0) return 0;
  15.  
  16. unordered_map<ll, int> mp;
  17.  
  18. int l = 1;
  19. ll distinct = 0;
  20. ll res = 0;
  21.  
  22. for (int r = 1; r <= n; r++)
  23. {
  24. if (mp[arr[r]] == 0) distinct++;
  25. mp[arr[r]]++;
  26.  
  27. while (distinct > K)
  28. {
  29. mp[arr[l]]--;
  30. if (mp[arr[l]] == 0) distinct--;
  31. l++;
  32. }
  33.  
  34. res += r - l + 1;
  35. }
  36.  
  37. return res;
  38. }
  39.  
  40. __luciousx__
  41. {
  42. fast;
  43.  
  44. ll m, u;
  45. cin >> n >> m >> u;
  46.  
  47. for (int i = 1; i <= n; i++)
  48. cin >> arr[i];
  49.  
  50. ll ans = khovl(u) - khovl(m - 1);
  51.  
  52. cout << ans;
  53. return 0;
  54. }
  55.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty