시간 제한메모리 제한제출정답맞힌 사람정답 비율
4 초 (추가 시간 없음) 1024 MB20141280.000%

문제

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 $a$ 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 $l$, $r$. For each query, the machine will be asked to compute the value of the implication of the subarray $a_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:

$x$ $y$ $x \to y$
$0$ $0$ $1$
$0$ $1$ $1$
$1$ $0$ $0$
$1$ $1$ $1$

In this problem, we assume a left-to-right evaluation order, so the order of the operations is $((\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 $n$ ($2\leq n\leq 10^5$), the size of the array.
  • One line with $n$ integers $a$ ($a \in \{0, 1\}$), the values in the array.
  • One line with an integer $q$ ($1\leq q\leq 10^5$), the number of queries.
  • $q$ lines, each with two integers $l$ and $r$ ($1 \leq l < r \leq n$), describing a query.

출력

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

예제 입력 1

5
0 0 1 1 0
5
1 2
2 3
4 5
3 4
1 5

예제 출력 1

1
1
0
1
0

예제 입력 2

7
1 0 0 0 1 0 0
5
1 3
4 7
2 4
3 6
1 7

예제 출력 2

1
1
0
0
1

출처

University > Delft University of Technology > Freshmen Programming Contest 2024 I번

  • 문제를 만든 사람: Makar Kuleshov