#include using namespace std; // one-based numbering struct UnionFind { vector data; // i: (data[i] < 0) -> group size, (data[i] > 0) -> parent; UnionFind(int n) { data.resize(n+1, -1); } int find(int x) { if(data[x] < 0) return x; else return data[x] = find(data[x]); } int size(int x) { return -data[find(x)]; } bool unite(int x, int y) { x = find(x); y = find(y); if(x == y) return false; if (data[x] > data[y]) swap(x, y); data[x] += data[y]; data[y] = x; return true; } bool same(int x, int y) { x = find(x); y = find(y); return x == y; } }; int main() { int n; cin >> n; vector a(n); for (int i = 0; i < n; i++) cin >> a[i]; UnionFind f(n), g(n); for (int i = 1; i < n; i++) { if (a[i-1] <= a[i]) f.unite(i, i+1); if (a[i-1] >= a[i]) g.unite(i, i+1); } int q; cin >> q; while (q--) { int l, r; cin >> l >> r; int fans = (int) f.same(l+1, r+1); int gans = (int) g.same(l+1, r+1); cout << fans << " " << gans << endl; } return 0; }