TLE '16 Contest 7 P3 - NOR

View as PDF

Submit solution


Points: 10 (partial)
Time limit: 0.75s
Memory limit: 256M

Author:
Problem type
A Venn diagram of ANORB from the Wikimedia Commons.

The only required knowledge is the NOR operator. All of its possible outputs can be stored concisely in this table.

a b aNORb
0 0 1
0 1 0
1 0 0
1 1 0

You are given a sequence A consisting of 0's and 1's. Here, the ith element of A is denoted with Ai. A has length N (2N106), and is indexed from 1 to N.

There are Q (1Q105) queries, with each query consisting of integers x and y (1x<yN). For each query, output the value of (AxNORAx+1NORNORAy1NORAy) by itself on a line. Because the NOR operator is not associative, please evaluate the operations from left to right.

Input Specification

The first line contains one integer, N (2N106).

The second line contains N space-separated integers. The ith integer is Ai.

The third line contains one integer, Q (1Q105).

The following Q lines contain two space-separated integers, x and y (1x<yN).

Subtask Points Additional Constraints
1 20 N=2, Q=1
2 20 N2000, Q2000
3 60 No additional constraints.

Output Specification

For each query, output the result of (AxNORAx+1NORNORAy1NORAy). The operations should be evaluated from left to right.

Sample Input

Copy
6
0 1 1 0 0 1
5
1 2
2 6
3 5
4 5
5 6

Sample Output

Copy
0
0
1
1
0

Comments


  • -4
    franklai  commented on March 24, 2017, 1:29 p.m.

    How come when input is 3 5, and the A string is 0 1 1 0 0 1 the output is 1? It should process 1 0 0 which gives a value of 0 when processed with nor?


    • 1
      Paradox  commented on March 24, 2017, 1:38 p.m.

      1 NOR 0 NOR 0 = ((1 NOR 0) NOR 0) = (0 NOR 0) = 1