#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define int ll #define INT128_MAX (__int128)(((unsigned __int128) 1 << ((sizeof(__int128) * __CHAR_BIT__) - 1)) - 1) #define INT128_MIN (-INT128_MAX - 1) #define pb push_back #define eb emplace_back #define clock chrono::steady_clock::now().time_since_epoch().count() using namespace std; template ostream& operator<<(ostream& os, const pair pr) { return os << pr.first << ' ' << pr.second; } template ostream& operator<<(ostream& os, const array &arr) { for(size_t i = 0; T x : arr) { os << x; if (++i != N) os << ' '; } return os; } template ostream& operator<<(ostream& os, const vector &vec) { for(size_t i = 0; T x : vec) { os << x; if (++i != size(vec)) os << ' '; } return os; } template ostream& operator<<(ostream& os, const set &s) { for(size_t i = 0; T x : s) { os << x; if (++i != size(s)) os << ' '; } return os; } template ostream& operator<<(ostream& os, const map &m) { for(size_t i = 0; pair x : m) { os << x; if (++i != size(m)) os << ' '; } return os; } #ifdef DEBUG #define dbg(...) cerr << '(', _do(#__VA_ARGS__), cerr << ") = ", _do2(__VA_ARGS__) template void _do(T &&x) { cerr << x; } template void _do(T &&x, S&&...y) { cerr << x << ", "; _do(y...); } template void _do2(T &&x) { cerr << x << endl; } template void _do2(T &&x, S&&...y) { cerr << x << ", "; _do2(y...); } #else #define dbg(...) #endif using ll = long long; using ull = unsigned long long; using ldb = long double; using pii = pair; using pll = pair; //#define double ldb template using min_heap = priority_queue, greater>; template using max_heap = priority_queue; template, class OP = plus> void pSum(rng &&v) { if (!v.empty()) for(T p = v[0]; T &x : v | views::drop(1)) x = p = OP()(p, x); } template, class OP> void pSum(rng &&v, OP op) { if (!v.empty()) for(T p = v[0]; T &x : v | views::drop(1)) x = p = op(p, x); } template void Unique(rng &v) { ranges::sort(v); v.resize(unique(v.begin(), v.end()) - v.begin()); } template rng invPerm(rng p) { rng ret = p; for(int i = 0; i < ssize(p); i++) ret[p[i]] = i; return ret; } template rng Permute(rng v, rng2 p) { rng ret = v; for(int i = 0; i < ssize(p); i++) ret[p[i]] = v[i]; return ret; } template vector> readGraph(int n, int m, int base) { vector> g(n); for(int i = 0; i < m; i++) { int u, v; cin >> u >> v; u -= base, v -= base; g[u].emplace_back(v); if constexpr (!directed) g[v].emplace_back(u); } return g; } template void setBit(T &msk, int bit, bool x) { msk = (msk & ~(T(1) << bit)) | (T(x) << bit); } template void flipBit(T &msk, int bit) { msk ^= T(1) << bit; } template bool getBit(T msk, int bit) { return msk >> bit & T(1); } template T floorDiv(T a, T b) { if (b < 0) a *= -1, b *= -1; return a >= 0 ? a / b : (a - b + 1) / b; } template T ceilDiv(T a, T b) { if (b < 0) a *= -1, b *= -1; return a >= 0 ? (a + b - 1) / b : a / b; } template bool chmin(T &a, T b) { return a > b ? a = b, 1 : 0; } template bool chmax(T &a, T b) { return a < b ? a = b, 1 : 0; } // note: g = floor(x / val) is the greatest value s.t. floor(x / g) = val for floor sum, // g = ceil(x / val) is the least value s.t. ceil(x / g) = val for ceil sum. // template vector> calc_floor(T x) { vector v, rng; for(T i = x; i; ) { T val = x / i; v.emplace_back(val); rng.emplace_back(x / val); i = x / (val + 1); } rng.emplace_back(0); vector> res; for(int i = 0; i < ssize(v); i++) res.push_back({v[i], rng[i + 1] + 1, rng[i]}); //{q, [l, r]} return res; } template vector> calc_ceil(T x) { vector v, rng; for(T i = 1; ; ) { T val = (x + i - 1) / i; v.emplace_back(val); rng.emplace_back((x + val - 1) / val); if (val == 1) break; i = (x + val - 2) / (val - 1); } rng.emplace_back(x + 1); vector> res; for(int i = 0; i < ssize(v); i++) res.push_back({v[i], rng[i], rng[i + 1] - 1}); //{q, [l, r]} return res; } signed main() { ios::sync_with_stdio(false), cin.tie(NULL); dbg(calc_floor(10)); int n; cin >> n; vector s(n); for(int &x : s) cin >> x; vector si(n); for(int i = 0; i < n; i++) si[i] = pair(s[i], i); ranges::sort(si); ranges::sort(s); map xs; { int q; cin >> q; vector tf(q); for(auto &[t, f] : tf) cin >> t >> f; int l = tf[0].first, r = tf[0].first; for(auto [t, f] : tf) { if (t <= r) r += f; else xs[r - l]++, l = t, r = t + f; } xs[r - l]++; } vector v(n); for(auto [x, f] : xs) { int r0 = n; for(int pre = 0; auto [q, l, r] : calc_floor(x)) { int i = upper_bound(s.begin(), s.begin() + r0, r) - s.begin() - 1; if (i >= 0) v[i] += f * (q - pre); pre = q, r0 = i + 1; } } for(int i = n - 2; i >= 0; i--) v[i] += v[i + 1]; vector ans(n); for(int i = 0; i < n; i++) ans[si[i].second] = v[i]; for(int x : ans) cout << x << '\n'; return 0; }