Advertisement
Ankit_132

D

Apr 8th, 2024
3,190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll     long long
  6. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  7. #define pb     push_back
  8. #define ppb    pop_back
  9. #define pf     push_front
  10. #define ppf    pop_front
  11.  
  12. int main()
  13. {
  14.     _test
  15.     {
  16.         int n, m, k;
  17.         cin>>n>>m>>k;
  18.  
  19.         vector<int> a(n), b(m);
  20.  
  21.         for(auto &e: a)     cin>>e;
  22.         for(auto &e: b)     cin>>e;
  23.  
  24.         map<int, int> cnta, cntb;
  25.  
  26.         for(auto e: b)              cntb[e]++;
  27.         for(int i=0; i<m; i++)      cnta[a[i]]++;
  28.  
  29.         int ans = 0;
  30.         int c = 0;
  31.  
  32.         for(auto [e, _]: cntb)      c += min(cnta[e], cntb[e]);
  33.  
  34.         ans += (c >= k);
  35.  
  36.         for(int i=m; i<n; i++)
  37.         {
  38.             cnta[a[i-m]]--;
  39.             if(cntb[a[i-m]] > cnta[a[i-m]]) c--;
  40.  
  41.             cnta[a[i]]++;
  42.             if(cnta[a[i]] <= cntb[a[i]])    c++;
  43.  
  44.             ans += (c >= k);
  45.         }
  46.  
  47.         cout<<ans<<"\n";
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement