#include <bits/stdc++.h>
using namespace std;
//Function to find first index of element in array a
//greater than x, you can using upper_bound too.
int upper(int a[], int l, int r, int x){
int res = -1 ;
while(l <= r){
int m = (l+r) / 2;
if(a[m] > x){
res = m ;
r = m - 1;
}
else{
l = m + 1;
}
}
return res;
}
int cnt[5];
int dem(int y[], int m, int x){
if(x==0) return 0;
else if (x == 1) return cnt[0];
int ans = cnt[0] + cnt[1];
int i1 = upper(y, 0, m-1, x);
if(i1!=-1) ans += m - i1;
if(x==2) ans = ans - cnt[3] - cnt[4];
if(x==3) ans += cnt[2];
return ans;
}
void TC(){
int n, m ; cin >> n >> m;
memset(cnt, 0 , sizeof(cnt));
int x[n], y[m];
for(int i = 0; i < n; i++){
cin >> x[i];
}
for(int i = 0; i < m; i++){
cin >> y[i];
if(y[i] <= 4){
cnt[y[i]]++;
}
}
sort(y, y + m);
long long ans = 0;
for(int i = 0; i < n; i++){
ans += dem(y, m, x[i]);
}
cout << ans << endl;
}
int main(){
int t; cin >> t;
while(t--){
TC();
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgovL0Z1bmN0aW9uIHRvIGZpbmQgZmlyc3QgaW5kZXggb2YgZWxlbWVudCBpbiBhcnJheSBhCi8vZ3JlYXRlciB0aGFuIHgsIHlvdSBjYW4gdXNpbmcgdXBwZXJfYm91bmQgdG9vLgppbnQgdXBwZXIoaW50IGFbXSwgaW50IGwsIGludCByLCBpbnQgeCl7CglpbnQgcmVzID0gLTEgOwoJd2hpbGUobCA8PSByKXsKCQlpbnQgbSA9IChsK3IpIC8gMjsKCQlpZihhW21dID4geCl7CgkJCXJlcyA9IG0gOwoJCQlyID0gbSAtIDE7CgkJfQoJCWVsc2V7CgkJCWwgPSBtICsgMTsKCQl9Cgl9CglyZXR1cm4gcmVzOwp9CgppbnQgY250WzVdOwoKaW50IGRlbShpbnQgeVtdLCBpbnQgbSwgaW50IHgpewoJaWYoeD09MCkgcmV0dXJuIDA7CgllbHNlIGlmICh4ID09IDEpIHJldHVybiBjbnRbMF07CglpbnQgYW5zID0gY250WzBdICsgY250WzFdOwoJaW50IGkxID0gdXBwZXIoeSwgMCwgbS0xLCB4KTsKCWlmKGkxIT0tMSkgYW5zICs9IG0gLSBpMTsKCWlmKHg9PTIpIGFucyA9IGFucyAtIGNudFszXSAtIGNudFs0XTsKCWlmKHg9PTMpIGFucyArPSBjbnRbMl07CglyZXR1cm4gYW5zOwp9CgoKdm9pZCBUQygpewoJaW50IG4sIG0gOyBjaW4gPj4gbiA+PiBtOwoJbWVtc2V0KGNudCwgMCAsIHNpemVvZihjbnQpKTsKCWludCB4W25dLCB5W21dOwoJZm9yKGludCBpID0gMDsgaSA8IG47IGkrKyl7CgkJY2luID4+IHhbaV07Cgl9Cglmb3IoaW50IGkgPSAwOyBpIDwgbTsgaSsrKXsKCQljaW4gPj4geVtpXTsKCQlpZih5W2ldIDw9IDQpewoJCQljbnRbeVtpXV0rKzsKCQl9Cgl9Cglzb3J0KHksIHkgKyBtKTsKCWxvbmcgbG9uZyBhbnMgPSAwOwoJZm9yKGludCBpID0gMDsgaSA8IG47IGkrKyl7CgkJYW5zICs9IGRlbSh5LCBtLCB4W2ldKTsKCX0KCWNvdXQgPDwgYW5zIDw8IGVuZGw7Cn0KaW50IG1haW4oKXsKCWludCB0OyBjaW4gPj4gdDsKCXdoaWxlKHQtLSl7CgkJVEMoKTsKCX0KfQ==
Main.java:1: error: illegal character: '#'
#include <bits/stdc++.h>
^
Main.java:1: error: class, interface, or enum expected
#include <bits/stdc++.h>
^
Main.java:6: error: class, interface, or enum expected
int upper(int a[], int l, int r, int x){
^
Main.java:8: error: class, interface, or enum expected
while(l <= r){
^
Main.java:10: error: class, interface, or enum expected
if(a[m] > x){
^
Main.java:12: error: class, interface, or enum expected
r = m - 1;
^
Main.java:13: error: class, interface, or enum expected
}
^
Main.java:16: error: class, interface, or enum expected
}
^
Main.java:19: error: class, interface, or enum expected
}
^
Main.java:23: error: class, interface, or enum expected
int dem(int y[], int m, int x){
^
Main.java:25: error: class, interface, or enum expected
else if (x == 1) return cnt[0];
^
Main.java:26: error: class, interface, or enum expected
int ans = cnt[0] + cnt[1];
^
Main.java:27: error: class, interface, or enum expected
int i1 = upper(y, 0, m-1, x);
^
Main.java:28: error: class, interface, or enum expected
if(i1!=-1) ans += m - i1;
^
Main.java:29: error: class, interface, or enum expected
if(x==2) ans = ans - cnt[3] - cnt[4];
^
Main.java:30: error: class, interface, or enum expected
if(x==3) ans += cnt[2];
^
Main.java:31: error: class, interface, or enum expected
return ans;
^
Main.java:32: error: class, interface, or enum expected
}
^
Main.java:36: error: class, interface, or enum expected
int n, m ; cin >> n >> m;
^
Main.java:37: error: class, interface, or enum expected
memset(cnt, 0 , sizeof(cnt));
^
Main.java:38: error: class, interface, or enum expected
int x[n], y[m];
^
Main.java:39: error: class, interface, or enum expected
for(int i = 0; i < n; i++){
^
Main.java:39: error: class, interface, or enum expected
for(int i = 0; i < n; i++){
^
Main.java:39: error: class, interface, or enum expected
for(int i = 0; i < n; i++){
^
Main.java:41: error: class, interface, or enum expected
}
^
Main.java:42: error: class, interface, or enum expected
for(int i = 0; i < m; i++){
^
Main.java:42: error: class, interface, or enum expected
for(int i = 0; i < m; i++){
^
Main.java:44: error: class, interface, or enum expected
if(y[i] <= 4){
^
Main.java:46: error: class, interface, or enum expected
}
^
Main.java:49: error: class, interface, or enum expected
long long ans = 0;
^
Main.java:50: error: class, interface, or enum expected
for(int i = 0; i < n; i++){
^
Main.java:50: error: class, interface, or enum expected
for(int i = 0; i < n; i++){
^
Main.java:50: error: class, interface, or enum expected
for(int i = 0; i < n; i++){
^
Main.java:52: error: class, interface, or enum expected
}
^
Main.java:54: error: class, interface, or enum expected
}
^
Main.java:56: error: class, interface, or enum expected
int t; cin >> t;
^
Main.java:57: error: class, interface, or enum expected
while(t--){
^
Main.java:59: error: class, interface, or enum expected
}
^
38 errors