#include #include using namespace atcoder; using namespace std; using ll = long long; ll INF = (1LL << 60); ll op(ll a, ll b) { return min(a, b); } ll e() { return INF; } int main() { int N;cin >> N; vector P(N + 1, 0); vectorA(N + 1, 0); for (int i = 1;i <= N;i++)cin >> P[i]; for (int i = 1;i <= N;i++) cin >> A[i]; vector S(N + 1, 0); for (int i = 1;i <= N;i++) S[i] = S[i - 1] + P[i]; segtree seg(P); vector ans(N + 1, 0); for (int i = 1;i <= N;i++) { ll x = P[i]; int ok = i; int ng = 0; while (ok - ng > 1) { int m = (ok + ng) / 2; if (seg.prod(m, i + 1) != x) { ng = m; } else { ok = m; } } int L = ok; ok = i; ng = N + 1; while (ng - ok > 1) { int m = (ok + ng) / 2; if (seg.prod(i, m + 1) != x) { ng = m; } else { ok = m; } } int R = ok; if (i - L >= R - i) { for (int j = i;j <= R;j++) { auto itr = lower_bound(S.begin(), S.end(), S[j] - A[x]); int t = itr - S.begin(); if (t + 1 > i) continue; int st = max(t + 1, L); ans[x] += i - st + 1; } } else { for (int j = i;j >= L;j--) { auto itr = upper_bound(S.begin(), S.end(), S[j - 1] + A[x]); itr--; int t = itr - S.begin(); if (t < i) continue; int ed = min(t, R); ans[x] += ed - i + 1; } } } for (int x = 1;x <= N;x++) cout << ans[x] << endl; }