AND vs OR
Time limit2sMemory limit1024 MB
For each query range, sum the positive values of (first AND last) minus the OR of the inner elements over all subarrays, modulo 1000000007.
- Level
Hard8 of 10
- Topics
- Bit manipulation, Divide and conquer, Prefix sum
- Solved
- No attempts yet
Problem
The value of a sequence is defined as follows.
- If the length is 2 or less, the value of the sequence is .
- If the length is 3 or more, the value of the sequence is .
is the bitwise and operator, and is the bitwise or operator.
You are given a sequence of integers .
Write a program that processes the following query times.
- : Find the sum of all positive values among the values of every contiguous subsequence of , and print it.
Input
The first line contains an integer .
The second line contains the sequence as integers separated by spaces.
The third line contains an integer , the number of queries.
From the fourth line, the next lines each contain two integers and separated by a space.
Output
For each query, print the answer on its own line.
Since the answer can be very large, print it modulo .