686MS
1 #include <iostream> 2 #include <cstdlib> 3 #include <cstdio> 4 #include <algorithm> 5 6 using namespace std; 7 8 int a[100010]; 9 10 int n; 11 12 bool bsearch(int key) 13 { 14 int lo = 0,hi = n-1,mid = lo+(hi-lo)/2; 15 while(lo<=hi) 16 { 17 if(key==a[mid]) 18 return true; 19 else if(key >a[mid]) 20 { 21 lo = mid+1; 22 mid = lo+(hi-lo)/2; 23 24 } 25 else 26 { 27 hi = mid-1; 28 mid =lo+(hi-lo)/2; 29 } 30 } 31 return false; 32 } 33 34 int main() 35 { 36 int t,m,i; 37 scanf("%d",&t); 38 while (t--) 39 { 40 scanf("%d%d",&n,&m); 41 for(i = 0;i<n;i++) 42 scanf("%d",&a[i]); 43 int count = 0; 44 45 sort(a,a+n); 46 47 for(i = 0;i<n;i++) 48 { 49 if(a[i]>m/2) break; 50 51 if(a[i] == a[i-1]) 52 continue; 53 54 if(2*a[i]==m) 55 count++; 56 else if(bsearch(m-a[i])) 57 count+=2; 58 } 59 printf("%d ",count); 60 } 61 return 0; 62 }