1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
#include <bits/stdc++.h> #define FOR(i, a, b) for (long long i = (a); i <= (b); ++i) #define ROF(i, a, b) for (long long i = (a); i >= (b); --i) #define all(x) x.begin(),x.end() #define CLR(i,a) memset(i,a,sizeof(i)) #define fi first #define se second #define pb push_back #define SZ(a) ((int) a.size())
using namespace std;
typedef long long ll; typedef unsigned long long ull; typedef pair<ll,ll> pll; typedef array<ll,4> arr; typedef double DB; typedef pair<DB,DB> pdd; constexpr ll MAXN=static_cast<ll>(2e5)+10,INF=static_cast<ll>(5e18)+3; constexpr double eps=1e-10;
ll N,T,A[MAXN];
inline void solve(){ cin>>N; for(int i=1;i<=N;++i){ cin>>A[i]; } sort(A+1,A+1+N); ll Q; cin>>Q; for(int i=1;i<=Q;++i){ ll b,c; cin>>b>>c; b=-b; ll D=b*b-4*1*c; if(D<0){ cout<<0<<" "; continue; } long double sqD=sqrt(D);
ll fsqD=floor(sqD); if(fsqD*fsqD!=D){ cout<<0<<" "; continue; } if(D!=0){ if((-b+fsqD)%2!=0 || (-b-fsqD)%2!=0){ cout<<0<<" "; continue; } ll x1=(-b+fsqD)/(2); ll x2=(-b-fsqD)/(2); ll num1=upper_bound(A+1,A+1+N,x1)-lower_bound(A+1,A+1+N,x1); ll num2=upper_bound(A+1,A+1+N,x2)-lower_bound(A+1,A+1+N,x2); cout<<num1*num2<<" ";
}else{ ll needFind=(-b)/(2); ll num=upper_bound(A+1,A+1+N,needFind)-lower_bound(A+1,A+1+N,needFind); cout<<num*(num-1)/2<<" "; } } cout<<"\n"; }
int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); cin>>T; while(T--){ solve(); } return 0; }
|