#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef pair pli; typedef pair pil; typedef pair pll; typedef pair pii; typedef pair pdd; typedef pair piii; typedef pair pil; typedef pair plii; typedef pair pdi; typedef long long ll; typedef unsigned long long ull; typedef pair puu; typedef long double ld; const int N = 2000086, MOD = 1e9 + 7, INF = 0x3f3f3f3f, MID = 333; const long double EPS = 1e-9; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; // int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; // int dx[8] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[8] = {1, 2, 2, 1, -1, -2, -2, -1}; int n, m, cnt; int w[N]; vector num; ll res; ll lowbit(ll x) { return x & -x; } ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; } inline double rand(double l, double r) { return (double)rand() / RAND_MAX * (r - l) + l; } inline ll qmi(ll a, ll b, ll c) { ll res = 1; while (b) { if (b & 1) res = res * a % c; a = a * a % c; b >>= 1; } return res; } inline ll qmi(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res *= a; a *= a; b >>= 1; } return res; } inline double qmi(double a, ll b) { double res = 1; while (b) { if (b & 1) res *= a; a *= a; b >>= 1; } return res; } inline ll C(ll a, ll b, int* c) { if (a < b) return 0; ll res = 1; for (ll j = a, i = 1; i < b + 1; i++, j--) res *= j; for (ll j = a, i = 1; i < b + 1; i++, j--) res /= i; return res; } inline int find_(int x) { return lower_bound(num.begin(), num.end(), x) - num.begin(); } const int logn = 19; const int maxn = 200008; int f[maxn][logn + 1], Logn[maxn + 1]; int ans[N]; void pre() { Logn[1] = 0; Logn[2] = 1; for (int i = 3; i < maxn; i++) { Logn[i] = Logn[i / 2] + 1; } } int query(int l, int r) { int s = Logn[r - l + 1]; return max(f[l][s], f[r - (1 << s) + 1][s]); } struct cc { bool operator()(const pii& a, const pii& b) const { return a.second - a.first != b.second - b.first ? a.second - a.first > b.second - b.first : a.first < b.first; } }; int main() { pre(); cin >> n; for (int i = 1; i < n + 1; i++) scanf("%d", w + i), f[i][0] = w[i]; for (int j = 1; j <= logn; j++) for (int i = 1; i + (1 << j) - 1 <= n; i++) f[i][j] = max(f[i][j - 1], f[i + (1 << (j - 1))][j - 1]); cin >> m; map ma; while (m--) { int l, r; scanf("%d%d", &l, &r); int maxn = w[r], len = 2; r--; while (l <= r) { int c = (r - l + 1) % len; if (!c) { ma[{l, l + len - 1}]++; maxn = max(maxn, query(l, l + len - 1)); l += len; } else { if (r > r - len / 2 + 1) ma[{r - len / 2 + 1, r}]++; maxn = max(maxn, query(r - len / 2 + 1, r)); r -= len / 2; } ans[maxn]++; len <<= 1; } } while (ma.size()) { auto u = *ma.begin(); ma.erase(ma.begin()); int l = u.first.first, r = u.first.second; ans[query(l, r)] += u.second; if (r - l != 1) { ma[{l, (r - l + 1) / 2 + l - 1}] += u.second; ma[{l + (r - l + 1) / 2, r}] += u.second; } } for (int i = 1; i < n + 1; i++) printf("%d\n", ans[i]); return 0; }