#P9335. [Ynoi2001] 雪に咲く花
[Ynoi2001] 雪に咲く花
Background
I do not need anything.
I no longer ask for anything.
As long as you are here, it is enough.
As long as we are together.
Quietly turning my face aside, holding my breath.
It feels like, if I blink,
you might suddenly disappear.
So let me keep staring; I like you.
Ah, the trees tremble, and the snow begins to fall.
Only two lines of white footprints remain.
Time, pile up.
Time, pile up.
In my hair, in my chest, in the dream that belongs only to the two of us,
the seeds of a flower that cannot bloom
snuggle close, embraced by the snow.
I just want to be quietly forgotten.

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 . For each query, compute the sum of the values of all sub-intervals that satisfy .
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 containing one integer representing the corresponding answer. Output the answer 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
Idea: nzhtl1477, Solution: ccz181078, Code: ccz181078, Data: ccz181078.
For of the testdata, it holds that:
Efficient I/O is recommended.
Translated by ChatGPT 5