Huge Sequences
Time limit1sMemory limit2048 MB
Given three arrays, answer queries asking for the sum over all subintervals of a range of the product of AND of a, OR of b, and GCD of c, modulo 2^32.
- Level
Hard10 of 10
- Topics
- Divide and conquer, Bit manipulation, Number theory, Prefix sum
- Solved
- No attempts yet
Problem
You are given three sequences , , and . The value of an interval is the product of three factors: the bitwise AND of , the bitwise OR of , and the greatest common divisor of .
There are queries. Each query gives an interval and asks for the sum of the values of all intervals with . Report each answer modulo .
Input
The first line contains two integers and (, ).
The second line contains integers .
The third line contains integers .
The fourth line contains integers . Every , , and satisfies .
Each of the following lines contains two integers and (), describing one query.
Output
Print lines. The -th line contains the answer to the -th query modulo .