#include using namespace std; typedef long long ll; typedef pair P; #define DUMP(x) cout << #x << " = " << (x) << endl; #define FOR(i, m, n) for (ll i = m; i < n; i++) #define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) #define FOREACH(x, a) for (auto&(x) : (a)) #define ALL(v) (v).begin(), (v).end() #define SZ(x) ll(x.size()) int main() { ll n; cin >> n; vector a(n); REP(i, n) cin >> a[i]; vector inc(n), dec(n); iota(ALL(inc), 0); iota(ALL(dec), 0); ll i = 1, p = 0; while (i <= n) { if (i == n || a[i - 1] > a[i]) { FOR(j, p, i) { inc[j] = i - 1; } p = i; } i++; } i = 1, p = 0; while (i <= n) { if (i == n || a[i - 1] < a[i]) { FOR(j, p, i) { dec[j] = i - 1; } p = i; } i++; } // REP(i, n) { // DUMP(i); // DUMP(inc[i]); // DUMP(dec[i]); // } ll q; cin >> q; while (q--) { ll l, r; cin >> l >> r; vector ans(2, 0); if (r <= inc[l]) ans[0] = 1; if (r <= dec[l]) ans[1] = 1; REP(i, 2) cout << ans[i] << " \n"[i == 1]; } }