Huge Sequences

시간 제한1초메모리 제한2048 MB

요약
각 질의 구간 안의 모든 부분 구간에 대해 a의 AND, b의 OR, c의 GCD를 곱한 값을 더해 2^32로 나눈 나머지를 구한다.
난이도

어려움10점 중 10점

유형
세그먼트 트리, 분할 정복, 정수론, 누적 합
정답자
아직 제출이 없습니다

문제

Given three sequences a_1,…,a_na\_1, \ldots, a\_n, b_1,…,b_nb\_1, \ldots, b\_n, and c_1,…,c_nc\_1, \ldots, c\_n, define the value of the interval \[ℓ,r]\[\ell, r] as the product of three factors:

  • the bitwise AND of (a_ℓ,…,a_r)(a\_{\ell}, \ldots, a\_{r}),
  • the bitwise OR of (b_ℓ,…,b_r)(b\_{\ell}, \ldots, b\_{r}), and
  • the greatest common divisor of (c_ℓ,…,c_r)(c\_{\ell}, \ldots, c\_{r}).

There are mm queries. Each query provides an interval \[ℓ,r]\[\ell, r], and asks for the sum of the values of all intervals \[ℓ′,r′]\[\ell', r'] such that ℓ≤ℓ′≤r′≤r\ell \le \ell' \le r' \le r. As the answer may be large, find it modulo 2322^{32}.

입력

The first line of input contains two integers nn and mm (1≤n≤1061 \le n \le 10^6; 1≤m≤5⋅1061 \le m \le 5 \cdot 10^6).

The second line contains nn integers a_1,…,a_na\_1, \ldots, a\_n.

The third line contains nn integers b_1,…,b_nb\_1, \ldots, b\_n.

The fourth line contains nn integers c_1,…,c_nc\_1, \ldots, c\_n.

The constraints are: 1≤a_i,b_i,c_i≤n1 \le a\_i, b\_i, c\_i \le n.

Each of the following mm lines contains two integers ℓ\ell and rr and represents a query (1≤ℓ≤r≤n1 \le \ell \le r \le n).

출력

Output mm lines, each containing one integer: the corresponding answer modulo 2322^{32}.

예제2

  1. 예제 1

    입력
    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
    
  2. 예제 2

    입력
    1 1
    1
    1
    1
    1 1
    
    예상 출력
    1