/* -*- coding: utf-8 -*- * * 905.cc: No.905 Sorted? - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 100000; const int MAX_E2 = 1 << 18; // = 262144 const int INF = 1 << 30; /* typedef */ typedef pair pii; template struct SegTreeMinMax { int n, e2; T mins[MAX_E2], maxs[MAX_E2], mindef, maxdef; SegTreeMinMax() {} void init(int _n, T _mindef, T _maxdef) { n = _n; mindef = _mindef; maxdef = _maxdef; for (e2 = 1; e2 < n; e2 <<= 1); fill(mins, mins + MAX_E2, mindef); fill(maxs, maxs + MAX_E2, maxdef); } T &get_min(int i) { return mins[e2 - 1 + i]; } T &get_max(int i) { return maxs[e2 - 1 + i]; } void set(int i, T v) { get_min(i) = get_max(i) = v; } void set_all() { for (int j = e2 - 2; j >= 0; j--) { int j0 = j * 2 + 1, j1 = j0 + 1; mins[j] = min(mins[j0], mins[j1]); maxs[j] = max(maxs[j0], maxs[j1]); } } typedef pair ptt; ptt get_range(int r0, int r1, int k, int i0, int i1) { if (r1 <= i0 || i1 <= r0) return ptt(mindef, maxdef); if (r0 <= i0 && i1 <= r1) return ptt(mins[k], maxs[k]); int im = (i0 + i1) / 2; ptt v0 = get_range(r0, r1, k * 2 + 1, i0, im); ptt v1 = get_range(r0, r1, k * 2 + 2, im, i1); return ptt(min(v0.first, v1.first), max(v0.second, v1.second)); } ptt get_range(int r0, int r1) { return get_range(r0, r1, 0, 0, e2); } }; /* global variables */ int as[MAX_N]; SegTreeMinMax st; /* subroutines */ inline int cmpi(int a, int b) { if (a < b) return -1; if (a > b) return 1; return 0; } /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", as + i); st.init(n - 1, INF, -INF); for (int i = 0; i + 1 < n; i++) st.set(i, cmpi(as[i + 1], as[i])); st.set_all(); int qn; scanf("%d", &qn); while (qn--) { int l, r; scanf("%d%d", &l, &r); if (l == r) puts("1 1"); else { pii v = st.get_range(l, r); printf("%d %d\n", (v.first >= 0) ? 1 : 0, (v.second <= 0) ? 1 : 0); } } return 0; }