#include "iostream"
#include "algorithm"
#include "vector"
#include "set"
#include "map"
#include "cstring"
#include "string"
#include "vector"
#include "cassert"
#include "queue"
#include "cstdio"
#include "cstdlib"
using namespace std;
typedef long long ll;
typedef pair < int, int > ii;
const int N = 1e6 + 5;
int n, m, cnt, tick;
int a[N], gobig[N], gosmall[N], h[N], st[N], nd[N], root[N];
vector < int > g[N];
vector < ii > qu[N];
int fen[N], ans[N];
void dfs(int p, int x) {
st[x] = ++tick;
h[x] = 1;
for(auto u : g[x])
if(u != p)
dfs(x, u);
nd[x] = tick;
}
inline void up(int x, int y, int k) {
//printf("x = %d y = %d k = %d\n", x, y, k);
for(; y; y -= y & -y)
fen[y] += k;
for(x--; x; x -= x & -x)
fen[x] -= k;
}
inline int get(int x) {
int res = 0;
for(; x < N; x += x & -x)
res += fen[x];
return res;
}
void dfs2(int p, int x) {
int y = x > n ? x - n : x + n;
//printf("x = %d y = %d\n", x, y);
up(st[x], nd[x], +1);
up(st[y], nd[y], +1);
for(auto u : qu[x]) {
//printf("id = %d res = %d\n", u.second, get(st[u.first]));
ans[u.second] = get(st[u.first]);
}
h[x] = 1;
for(auto u : g[x])
if(u != p)
dfs2(x, u);
//printf("del x = %d y = %d\n", x, y);
up(st[x], nd[x], -1);
up(st[y], nd[y], -1);
}
int f(int x) {
if(x != root[x])
return root[x] = f(root[x]);
return x;
}
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
scanf("%d", a + i);
}
vector < ii > v;
for(int i = n; i >= 1; i--) {
while(!v.empty() and v.back().first <= a[i])
v.pop_back();
if(v.size()) {
gobig[i] = v.back().second;
}
v.push_back(ii(a[i], i));
}
v.clear();
for(int i = n; i >= 1; i--) {
while(!v.empty() and v.back().first >= a[i])
v.pop_back();
if(v.size()) {
gosmall[i] = v.back().second;
}
v.push_back(ii(a[i], i));
}
for(int i = 1; i <= n + n; i++)
root[i] = i;
for(int i = 1; i <= n; i++) {
if(gosmall[i]) {
g[gosmall[i] + n].push_back(i);
root[f(i)] = f(gosmall[i] + n);
}
if(gobig[i]) {
g[gobig[i]].push_back(i + n);
root[f(i + n)] = f(gobig[i]);
}
}
for(int i = 1; i <= n + n; i++) {
if(!h[f(i)]) {
cnt++;
dfs(0, f(i));
}
}
scanf("%d", &m);
for(int i = 1; i <= m; i++) {
int x, y;
scanf("%d %d", &x, &y);
qu[x].push_back(ii(y, i));
}
memset(h, 0, sizeof(h));
for(int i = 1; i <= n + n; i++) {
if(!h[f(i)]) {
dfs2(0, f(i));
}
}
for(int i = 1; i <= m; i++)
printf("%d\n", (bool) ans[i]);
return 0;
}
I2luY2x1ZGUgImlvc3RyZWFtIgojaW5jbHVkZSAiYWxnb3JpdGhtIgojaW5jbHVkZSAidmVjdG9yIgojaW5jbHVkZSAic2V0IgojaW5jbHVkZSAibWFwIgojaW5jbHVkZSAiY3N0cmluZyIKI2luY2x1ZGUgInN0cmluZyIKI2luY2x1ZGUgInZlY3RvciIKI2luY2x1ZGUgImNhc3NlcnQiCiNpbmNsdWRlICJxdWV1ZSIKI2luY2x1ZGUgImNzdGRpbyIKI2luY2x1ZGUgImNzdGRsaWIiCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdHlwZWRlZiBsb25nIGxvbmcgbGw7CnR5cGVkZWYgcGFpciA8IGludCwgaW50ID4gaWk7Cgpjb25zdCBpbnQgTiA9IDFlNiArIDU7CgppbnQgbiwgbSwgY250LCB0aWNrOwppbnQgYVtOXSwgZ29iaWdbTl0sIGdvc21hbGxbTl0sIGhbTl0sIHN0W05dLCBuZFtOXSwgcm9vdFtOXTsKdmVjdG9yIDwgaW50ID4gZ1tOXTsKdmVjdG9yIDwgaWkgPiBxdVtOXTsKaW50IGZlbltOXSwgYW5zW05dOwoKdm9pZCBkZnMoaW50IHAsIGludCB4KSB7CiAgICBzdFt4XSA9ICsrdGljazsKICAgIGhbeF0gPSAxOwogICAgZm9yKGF1dG8gdSA6IGdbeF0pCiAgICAgICAgaWYodSAhPSBwKQogICAgICAgICAgICBkZ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AgICAgIHJldHVybiByb290W3hdID0gZihyb290W3hdKTsKICAgIHJldHVybiB4Owp9CgppbnQgbWFpbigpIHsKICAgIAogICAgc2NhbmYoIiVkIiwgJm4pOwogICAgCiAgICBmb3IoaW50IGkgPSAxOyBpIDw9IG47IGkrKykgewogICAgICAgIHNjYW5mKCIlZCIsIGEgKyBpKTsKICAgIH0KICAgIAogICAgdmVjdG9yIDwgaWkgPiB2OwogICAgCiAgICBmb3IoaW50IGkgPSBuOyBpID49IDE7IGktLSkgewogICAgICAgIHdoaWxlKCF2LmVtcHR5KCkgYW5kIHYuYmFjaygpLmZpcnN0IDw9IGFbaV0pCiAgICAgICAgICAgIHYucG9wX2JhY2soKTsKICAgICAgICBpZih2LnNpemUoKSkgewogICAgICAgICAgICBnb2JpZ1tpXSA9IHYuYmFjaygpLnNlY29uZDsKICAgICAgICB9CiAgICAgICAgdi5wdXNoX2JhY2soaWkoYVtpXSwgaSkpOwogICAgfQogICAgCiAgICB2LmNsZWFyKCk7CiAgICAKICAgIGZvcihpbnQgaSA9IG47IGkgPj0gMTsgaS0tKSB7CiAgICAgICAgd2hpbGUoIXYuZW1wdHkoKSBhbmQgdi5iYWNrKCkuZmlyc3QgPj0gYVtpXSkKICAgICAgICAgICAgdi5wb3BfYmFjaygpOwogICAgICAgIGlmKHYuc2l6ZSgpKSB7CiAgICAgICAgICAgIGdvc21hbGxbaV0gPSB2LmJhY2soKS5zZWNvbmQ7CiAgICAgICAgfQogICAgICAgIHYucHVzaF9iYWNrKGlpKGFbaV0sIGkpKTsKICAgIH0KICAgIAogICAgZm9yKGludCBpID0gMTsgaSA8PSBuICsgbjsgaSsrKQogICAgICAgIHJvb3RbaV0gPSBpOwogICAgCiAgICBmb3IoaW50IGkgPSAxOyBpIDw9IG47IGkrKykgewogICAgICAgIGlmKGdvc21hbGxbaV0pIHsKICAgICAgICAgICAgZ1tnb3NtYWxsW2ldICsgbl0ucHVzaF9iYWNrKGkpOwogICAgICAgICAgICByb290W2YoaSldID0gZihnb3NtYWxsW2ldICsgbik7CiAgICAgICAgfQogICAgICAgIGlmKGdvYmlnW2ldKSB7CiAgICAgICAgICAgIGdbZ29iaWdbaV1dLnB1c2hfYmFjayhpICsgbik7CiAgICAgICAgICAgIHJvb3RbZihpICsgbildID0gZihnb2JpZ1tpXSk7CiAgICAgICAgfQogICAgfQogICAgCiAgICBmb3IoaW50IGkgPSAxOyBpIDw9IG4gKyBuOyBpKyspIHsKICAgICAgICBpZighaFtmKGkpXSkgewogICAgICAgICAgICBjbnQrKzsKICAgICAgICAgICAgZGZzKDAsIGYoaSkpOwogICAgICAgIH0KICAgIH0KICAgIAogICAgc2NhbmYoIiVkIiwgJm0pOwogICAgCiAgICBmb3IoaW50IGkgPSAxOyBpIDw9IG07IGkrKykgewogICAgICAgIGludCB4LCB5OwogICAgICAgIHNjYW5mKCIlZCAlZCIsICZ4LCAmeSk7CiAgICAgICAgcXVbeF0ucHVzaF9iYWNrKGlpKHksIGkpKTsKICAgIH0KICAgIAogICAgbWVtc2V0KGgsIDAsIHNpemVvZihoKSk7CiAgICAKICAgIGZvcihpbnQgaSA9IDE7IGkgPD0gbiArIG47IGkrKykgewogICAgICAgIGlmKCFoW2YoaSldKSB7CiAgICAgICAgICAgIGRmczIoMCwgZihpKSk7CiAgICAgICAgfQogICAgfQogICAgCiAgICBmb3IoaW50IGkgPSAxOyBpIDw9IG07IGkrKykKICAgICAgICBwcmludGYoIiVkXG4iLCAoYm9vbCkgYW5zW2ldKTsKICAgIAogICAgcmV0dXJuIDA7CiAgICAKfQ==