fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6. inline int power(int a, int b) {
  7. int x = 1;
  8. while (b) {
  9. if (b & 1) x *= a;
  10. a *= a;
  11. b >>= 1;
  12. }
  13. return x;
  14. }
  15.  
  16.  
  17. const int M = 1000000007;
  18. const int N = 3e5+9;
  19. const int INF = 2e9+1;
  20. const int LINF = 2000000000000000001;
  21.  
  22. //_ ***************************** START Below *******************************
  23.  
  24. vector<int> a;
  25.  
  26. int consistency(int n, int k, int d){
  27.  
  28. int ans = k;
  29.  
  30. unordered_map<int,int> mp;
  31. int s = 0, e = 0;
  32. while(e<n){
  33. mp[a[e]]++;
  34. if(e-s+1 < d){
  35. e++;
  36. }
  37. else{
  38.  
  39. int size = mp.size();
  40. ans = min(ans, size);
  41.  
  42. mp[a[s]]--;
  43. if(mp[a[s]] == 0) mp.erase(a[s]);
  44. s++;
  45. e++;
  46. }
  47. }
  48.  
  49.  
  50.  
  51. return ans;
  52. }
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65. int practice(int n, int k, int d){
  66.  
  67. return 0;
  68. }
  69.  
  70. void solve() {
  71.  
  72. int n, k, d;
  73. cin>>n >> k >> d;
  74.  
  75. a.resize(n);
  76. for(int i=0; i<n; i++) cin >> a[i];
  77.  
  78. cout << consistency(n, k, d) << endl;
  79.  
  80.  
  81. }
  82.  
  83.  
  84.  
  85.  
  86.  
  87. int32_t main() {
  88. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  89.  
  90. int t = 1;
  91. cin >> t;
  92. while (t--) {
  93. solve();
  94. }
  95.  
  96. return 0;
  97. }
Success #stdin #stdout 0s 5320KB
stdin
4
5 2 2
1 2 1 2 1
9 3 3
3 3 3 2 2 2 1 1 1
4 10 4
10 8 6 4
16 9 8
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3
stdout
2
1
4
5