#P8421. [THUPC 2022 决赛] rsraogps

[THUPC 2022 决赛] rsraogps

Problem Description

Given sequences a1,,ana_1,\dots,a_n, b1,,bnb_1,\dots,b_n, c1,,cnc_1,\dots,c_n.

Define the value of an interval [l,r][l,r] as the product of the following three quantities: the bitwise AND of al,,ara_l,\dots,a_r, the bitwise OR of bl,,brb_l,\dots,b_r, and the greatest common divisor of cl,,crc_l,\dots,c_r.

There are mm queries. Each query gives an interval [l,r][l,r], and asks for the sum of values over all subintervals [l,r][l',r'] satisfying llrrl\le l'\le r'\le r.

Input Format

The first line contains two integers n,mn,m.

The second line contains nn integers a1,,ana_1,\dots,a_n.

The third line contains nn integers b1,,bnb_1,\dots,b_n.

The fourth line contains nn integers c1,,cnc_1,\dots,c_n.

The next mm lines each contain two integers l,rl,r, representing one query.

Output Format

Output mm lines. Each line contains one integer, the answer for the corresponding query, output after taking modulo 2322^{32}.

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:

1n1061\le n\le 10^6.

1m5×1061\le m\le 5\times 10^6.

1ai,bi,cin1\le a_i,b_i,c_i\le n.

1lrn1\le l\le r\le n.

Efficient input/output methods are recommended.

Translated by ChatGPT 5