#include using namespace std; using ll = long long; using VI = vector; using VV = vector; using VS = vector; using PII = pair; // tourist set template string to_string(pair p); template string to_string(tuple p); template string to_string(tuple p); string to_string(const string& s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template string to_string(bitset v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast('0' + v[i]); } return res; } template string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template string to_string(pair p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template string to_string(tuple p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template string to_string(tuple p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cerr << '\n'; } template void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif // tourist set end templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b()) #define MP make_pair void no(){p_no(); exit(0);} void yes(){p_yes(); exit(0);} const ll mod = 1e9 + 7; const ll inf = 1e18; const double PI = acos(-1); // ei1333's BIT struct BinaryIndexedTree { VI data; BinaryIndexedTree(ll sz) { data.assign(++sz, 0); } ll sum(ll k) { ll ret = 0; for(++k; k > 0; k -= k & -k) ret += data[k]; return (ret); } // [i, j] ll range_sum(ll i, ll j){ if(i==0){ return sum(j); }else{ return sum(j) - sum(i-1); } } void add(ll k, ll x) { for(++k; k < data.size(); k += k & -k) data[k] += x; } }; int main(){ cin.tie(0); ios::sync_with_stdio(false); // input ll N; cin >> N; BinaryIndexedTree up(N); BinaryIndexedTree dw(N); VI A(N); rep(i, N){ cin >> A[i]; } rep(i, N-1){ if(A[i]A[i+1]){ dw.add(i, 1); } } ll Q; cin >> Q; while(Q--){ ll l, r; cin >> l >> r; ll a = up.range_sum(l, r-1); ll b = dw.range_sum(l, r-1); if(a==0 && b==0){ p("1 1"); } else if(a==0){ p("0 1"); } else if(b==0){ p("1 0"); } else{ p("0 0"); } } return 0; }