fork download
  1. #include<bits/stdc++.h>
  2. #define int long long
  3. using namespace std;
  4. signed main() {
  5. ios_base::sync_with_stdio(false);
  6. cin.tie(NULL);cout.tie(NULL);
  7. int q;
  8. cin >> q;
  9. int n, k;
  10. cin >> n >> k;
  11. int a[n + 1];
  12. map<int, int> b;
  13. for (int i = 1; i <= n; i++) {
  14. cin >> a[i];
  15. }
  16. int dem = 0, dem2 = 0, ans=0;
  17. for (int l = 1, r = 1; r <= n; r++) {
  18. if (b[a[r]] == 0) {
  19. dem++;
  20. b[a[r]]=1;
  21. }
  22. else b[a[r]]++;
  23. while (dem > k) {
  24. b[a[l]]--;
  25. if (b[a[l]] == 0) {
  26. dem--;
  27. }
  28. l++;
  29. }
  30. ans += r - l + 1;
  31. }
  32. cout << ans << "\n";
  33. return 0;
  34. }
  35.  
Runtime error #stdin #stdout 0.02s 5308KB
stdin
Standard input is empty
stdout
Standard output is empty