fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define maxn 100005
  4. using namespace std;
  5.  
  6. int t, n, m, x[maxn], y[maxn];
  7. int main()
  8. {
  9. cin >> t;
  10. while(t--){
  11. cin >> n >> m;
  12. for(int i = 0; i < n; ++i)
  13. cin >> x[i];
  14. int cnt[1005] = {};
  15. for(int j = 0; j < m; ++j)
  16. {
  17. cin >> y[j];
  18. cnt[y[j]]++;
  19. }
  20. int ans = 0;
  21. for(int i = 0; i < n; ++i){
  22. int k = m;
  23. if(x[i] == 1) ans += cnt[0];
  24. else if(x[i] == 3) ans += (k - cnt[3]);
  25. else if(x[i] == 2) ans += (k - cnt[2] - cnt[3] - cnt[4]);
  26. else if(x[i] >= 4){
  27. for(int j = 2; j <= x[i]; ++j)
  28. k -= cnt[j];
  29. ans += k;
  30. }
  31. }
  32. cout << ans << "\n";
  33. }
  34. return 0;
  35. }
Success #stdin #stdout 0.01s 5292KB
stdin
1
3 2
2 1 6
1 5
stdout
3