QOJ.ac

QOJ

Límite de tiempo: 3 s Límite de memoria: 512 MB Puntuación total: 100

#4322. rsraogps

Estadísticas

Given sequences $a_1, \dots, a_n$, $b_1, \dots, b_n$, and $c_1, \dots, c_n$.

Define the value of an interval $[l, r]$ as the product of the bitwise AND of $a_l, \dots, a_r$, the bitwise OR of $b_l, \dots, b_r$, and the greatest common divisor of $c_l, \dots, c_r$.

There are $m$ queries. Each query provides an interval $[l, r]$, and you are asked to find the sum of the values of all intervals $[l', r']$ such that $l \le l' \le r' \le r$.

Input

The first line contains two integers $n$ and $m$.

The second line contains $n$ integers $a_1, \dots, a_n$.

The third line contains $n$ integers $b_1, \dots, b_n$.

The fourth line contains $n$ integers $c_1, \dots, c_n$.

The next $m$ lines each contain two integers $l$ and $r$, representing a query.

$1 \le n \le 10^6$

$1 \le m \le 5 \times 10^6$

$1 \le a_i, b_i, c_i \le n$

$1 \le l \le r \le n$

Output

Output $m$ lines, each containing an integer representing the corresponding answer.

The answer should be output modulo $2^{32}$.

Examples

Input 1

5 3
3 3 1 1 1
2 1 3 2 2
4 5 3 4 4
1 2
2 5
4 5

Output 1

48
63
24

Note

It is recommended to use efficient input and output methods.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.