Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define pb push_back
- #define mp make_pair
- #define F first
- #define S second
- #define fo(i, n) for(int i = 1; i <= n; ++i)
- typedef long long ll;
- typedef pair<int, int> pii;
- typedef pair<ll, ll> pll;
- typedef long double ld;
- const int N = 40;
- const int K = 20;
- const int mod = 1e9 + 7;
- const ld eps = 1e-15L;
- int cnt[N], a[N], b[N];
- int n, q;
- ll res[40 * 100000];
- ld L[(1 << K)];
- ld R[(1 << K)];
- bool eq(ld x, ld y)
- {
- return abs(x - y) < eps;
- }
- int main()
- {
- scanf("%d", &n);
- for(int i = 0; i < n; ++i)
- scanf("%d", a + i);
- for(int i = 0; i < n; ++i)
- scanf("%d", b + i);
- int min_val = 0;
- for(int i = 0; i < n; ++i)
- min_val += a[i] / b[i];
- int m = (n + 1) >> 1;
- for(int i = 0; i < (1 << m); ++i)
- {
- ld s = 0.0;
- for(int j = 0; j < m; ++j)
- if((i >> j) & 1)
- s += a[j] / (b[j] + 0.0L);
- else
- s += a[j] / b[j];
- L[i] = s;
- }
- int h = n - m;
- for(int i = 0; i < ( 1 << h ); ++i)
- {
- ld s = 0.0;
- for(int j = 0; j < h; ++j)
- if((i >> j) & 1)
- s += a[j + m] / (b[j + m] + 0.0L);
- else
- s += a[j + m] / b[j + m];
- R[i] = s;
- }
- stable_sort(L, L + (1 << m));
- stable_sort(R, R + (1 << h));
- reverse(L, L + (1 << m));
- /* for(int i = 0; i < (1 << m); ++i)
- printf("%.3Lf ", L[i]);
- puts("");
- for(int i = 0; i < (1 << h); ++i)
- printf("%.3Lf ", R[i]);
- puts("");
- */
- int l = 0, r = -1;
- for(int check_val = min_val; check_val <= min_val + n; ++check_val)
- {
- l = 0, r = -1;
- for(int i = 0; i < (1 << h); ++i)
- {
- if(i == 0 || !eq(R[i], R[i - 1]) && R[i] + L[l] > ld(check_val) + eps)
- {
- l = r + 1;
- while(R[i] + L[l] > ld(check_val) + eps)
- ++l;
- r = l;
- while(r < (1 << m) && eq(L[l], L[r])) ++r;
- r--;
- }
- if(eq(check_val, R[i] + L[l]))
- res[check_val] += r - l + 1;
- }
- }
- scanf("%d", &q);
- while(q--) {
- int x;
- scanf("%d", &x);
- if(x >= 0 && x <= 40 * 100000)
- printf("%lld\n", res[x]);
- else
- puts("0");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement