#include using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) int n; long long x[100000]; bool f[400000], g[400000]; void fcalc(int k, int l, int r) { if (r - l == 1) { f[k] = true; } else { int mid = (l + r) / 2; fcalc(2 * k + 1, l, mid); fcalc(2 * k + 2, mid, r); f[k] = f[2 * k + 1] && f[2 * k + 2] && x[mid-1] <= x[mid]; } } void gcalc(int k, int l, int r) { if (r - l == 1) { g[k] = true; } else { int mid = (l + r) / 2; gcalc(2 * k + 1, l, mid); gcalc(2 * k + 2, mid, r); g[k] = g[2 * k + 1] && g[2 * k + 2] && x[mid-1] >= x[mid]; } } int fquery(int k, int l, int r, int a, int b) { if (a <= l && r <= b) return f[k]; if (b <= l || r <= a) return 1; int mid = (l + r) / 2; int ret = fquery(2 * k + 1, l, mid, a, b) && fquery(2 * k + 2, mid, r, a, b); if (a <= mid-1 && mid <= b) ret &= x[mid-1] <= x[mid]; return ret; } int gquery(int k, int l, int r, int a, int b) { if (a <= l && r <= b) return g[k]; if (b <= l || r <= a) return 1; int mid = (l + r) / 2; int ret = gquery(2 * k + 1, l, mid, a, b) && gquery(2 * k + 2, mid, r, a, b); if (a <= mid-1 && mid <= b) ret &= x[mid-1] >= x[mid]; return ret; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; REP (i, n) cin >> x[i]; fcalc(0, 0, n); gcalc(0, 0, n); int q; cin >> q; while (q--) { int l, r; cin >> l >> r; cout << fquery(0, 0, n, l, r) << " " << gquery(0, 0, n, l, r) << endl; } return 0; }