//include //------------------------------------------ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";} #define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}} using LL = long long; //------------------------------------------ //------------------------------------------ template class CulSum { private: long long N; vector a; vector aa; vector b; vector bb; function func; public: /// @param a original array CulSum(vector _a) { N = _a.size(); a = _a; b = _a; reverse(b.begin(), b.end()); this->aa = vector(N + 1, T{}); this->bb = vector(N + 1, T{}); for (int i = 0; i < N; i++) aa[i + 1] = a[i] + aa[i]; for (int i = 0; i < N; i++) bb[i + 1] = b[i] + bb[i]; } /// @param a original array CulSum(vector _a, function func) : func(func) { N = _a.size(); a = _a; b = _a; reverse(b.begin(), b.end()); this->aa = vector(N + 1, T{}); this->bb = vector(N + 1, T{}); for (int i = 0; i < N; i++) aa[i + 1] = func(a[i], aa[i]); for (int i = 0; i < N; i++) bb[i + 1] = func(b[i], bb[i]); } /// @brief 0-index original /// @param l original close /// @param r original open T get_sum(int l, int r) { return aa[r] - aa[l]; } /// @brief 0-index original /// @param l original close /// @param r original open T get_sum_reverse(int l, int r) { l = N - l; r = N - r; return bb[l] - bb[r]; } /// @brief 0-index original /// @param k length T get_sum_lead_k_len(int k) { return get_sum(0, k); } /// @brief 0-index original /// @param k length T get_sum_tail_k_len(int k) { return get_sum_reverse(N - k, N); } void show() { for (int i = 0; i < N + 1; i++) cout << aa[i] << " "; cout << endl; } void show_reverse() { for (int i = N; i >= 0; i--) cout << bb[i] << " "; cout << endl; } }; int main() { int N; cin >> N; vector A(N); for (int i = 0; i < N; i++) cin >> A[i]; vector B(N - 1); for (int i = 0; i < N - 1; i++) B[i] = (A[i + 1] - A[i]) >= 0; vector C(N - 1); for (int i = 0; i < N - 1; i++) C[i] = (A[i + 1] - A[i]) <= 0; CulSum culSum_B(B); CulSum culSum_C(C); int Q; cin >> Q; while (Q--) { int l, r; cin >> l >> r; if (culSum_B.get_sum(l, r) == r - l) cout << 1 << " "; else cout << 0 << " "; if (culSum_C.get_sum(l, r) == r - l) cout << 1 << endl; else cout << 0 << endl; } return 0; }