#P8421. [THUPC 2022 决赛] rsraogps
[THUPC 2022 决赛] rsraogps
Problem Description
Given sequences , , .
Define the value of an interval as the product of the following three quantities: 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 values over all subintervals satisfying .
Input Format
The first line contains two integers .
The second line contains integers .
The third line contains integers .
The fourth line contains integers .
The next lines each contain two integers , representing one query.
Output Format
Output lines. Each line contains one integer, the answer for the corresponding query, output after taking modulo .
5 3
3 3 1 1 1
2 1 3 2 2
4 5 3 4 4
1 2
2 5
4 5
48
63
24
Hint
Constraints:
.
.
.
.
Efficient input/output methods are recommended.
Translated by ChatGPT 5