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 100 101 102 103 104 105 106 107 108 109 110 111 112
| #include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <string> #include <vector> using namespace std;
#define dbg(x...) do { cout << #x << " -> "; err(x); } while (0) void err () { cout << endl;} template <class T, class... Ts> void err(const T& arg, const Ts&... args) { cout << arg << ' '; err(args...);}
#define ll long long #define LL __int128 #define inf 0x3f3f3f3f #define INF 0x3f3f3f3f3f3f3f3f #define pii pair<int, int> #define fi first #define se second #define pb push_back #define mp(a,b) make_pair(a,b) #define PAUSE system("pause"); const double Pi = acos(-1.0); const double eps = 1e-8; const int maxn = 5e5 + 10;
const int mod = 998244353; struct complex{ double x,y; complex (double xx = 0, double yy = 0){x = xx, y = yy;} }a[maxn],c[maxn]; int b[maxn]; complex operator + (complex a,complex b){ return complex(a.x + b.x, a.y + b.y); } complex operator - (complex a,complex b){ return complex(a.x - b.x, a.y - b.y); } complex operator * (complex a,complex b){ return complex(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x); } int n, m, u; int l, r[maxn]; int limit = 1; void fast_fast_tle(complex *A, int type) { for(int i=0;i<limit;i++) if(i<r[i]) swap(A[i],A[r[i]]); for(int mid=1;mid<limit;mid<<=1) { complex Wn( cos(Pi/mid) , type*sin(Pi/mid) ); for(int R=mid<<1,j=0;j<limit;j+=R) { complex w(1,0); for(int k=0;k<mid;k++,w=w*Wn) { complex x=A[j+k],y=w*A[j+mid+k]; A[j+k]=x+y; A[j+mid+k]=x-y; } } } } void solve() { scanf("%d", &n); ll num; ll c1 = 0, c2 = 0; for(int i = 1; i <= n; i++) { scanf("%lld", &num); a[num + 30000] = 1; c1 = max(c1, num + 30000); } scanf("%d", &m); for(int i = 1; i <= m; i++) { scanf("%lld", &num); b[i] = num + 30000; } scanf("%d", &u); for(int i = 1; i <= u; i++) { scanf("%lld", &num); c[num + 30000] = 1; c2 = max(c2, num + 30000); } while(limit <= c1 + c2) limit <<= 1, l++; for(int i = 0; i < limit; i++) r[i] = ( r[i>>1]>>1 )| ( (i&1)<<(l-1) ) ; fast_fast_tle(a, 1); fast_fast_tle(c, 1); for(int i = 0; i <= limit; i++) a[i] = a[i] * c[i]; fast_fast_tle(a, -1); ll ans = 0; for(int i = 1; i <= m; i++) ans += (int)(a[2 * b[i]].x / limit + 0.5); printf("%lld\n", ans); }
int main() { int t = 1; while(t--) solve(); return 0; }
|