Intelligence Exploration

시간 제한4초메모리 제한1024 MB

요약
각 질의마다 l번째부터 r번째까지의 이진 부분 배열을 왼쪽에서 오른쪽으로 함의 연산한 결과를 0 또는 1로 출력한다.
난이도

보통10점 중 4점

유형
누적 합, 배열
정답자
아직 제출이 없습니다

문제

John is a researcher working in the field of Artificial Intelligence. At the moment he needs to analyze reasoning abilities of a new Limitless Logic Machine, he wants to check how well it can understand when one thing implies another.

The scientist is planning to use a long array aa consisting of zeroes and ones for his experiment. During the experiment, he will make multiple queries to the machine, where each query is defined by a pair ll, rr. For each query, the machine will be asked to compute the value of the implication of the subarray a_l→a_l+1→…→a_ra\_l \to a\_{l + 1} \to \ldots \to a\_r. John asks you, as his AI Application Project Junior Engineer, to compute the correct answers for these queries, so he can use them to validate his machine.

The implication operator is defined as follows:

xxyyx→yx \to y
000011
001111
110000
111111

In this problem, we assume a left-to-right evaluation order, so the order of the operations is ((…((a_l→a_l+1)→a_l+2)→… )→a_r)((\dots((a\_l \to a\_{l + 1}) \to a\_{l + 2}) \to \dots) \to a\_r).

입력

The input consists of:

  • One line with an integer nn (2≤n≤1052\leq n\leq 10^5), the size of the array.
  • One line with nn integers aa (a∈0,1a \in \\{0, 1\\}), the values in the array.
  • One line with an integer qq (1≤q≤1051\leq q\leq 10^5), the number of queries.
  • qq lines, each with two integers ll and rr (1≤l<r≤n1 \leq l < r \leq n), describing a query.

출력

For each query, output the result of the corresponding implication.

예제2

  1. 예제 1

    입력
    5
    0 0 1 1 0
    5
    1 2
    2 3
    4 5
    3 4
    1 5
    
    예상 출력
    1
    1
    0
    1
    0
    
  2. 예제 2

    입력
    7
    1 0 0 0 1 0 0
    5
    1 3
    4 7
    2 4
    3 6
    1 7
    
    예상 출력
    1
    1
    0
    0
    1