Bitsets

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

요약
생성된 각 구간 질의마다 구간 안 모든 비트셋이 0이고 적어도 하나는 1인 위치의 개수를 세어 k개 질의의 합을 구한다.
난이도

보통10점 중 7점

유형
비트 연산, 누적 합, 구현
정답자
아직 제출이 없습니다

문제

Let us consider the following operations on bitsets of size mm:

  • c=a,and,bc = a\\, \mathrm{ and }\\, b. Here, c_i=1c\_i=1 if both a_ia\_i and b_ib\_i are equal to 11. Otherwise, c_i=0c\_i=0.
  • c=a,or,bc = a\\, \mathrm{ or }\\, b. Here, c_i=1c\_i=1 if either a_ia\_i or b_ib\_i is equal to 11. Otherwise, c_i=0c\_i=0.
  • c=a,xor,bc = a\\, \mathrm{ xor }\\, b. Here, c_i=1c\_i=1 if exactly one of a_ia\_i and b_ib\_i is equal to 11. Otherwise, c_i=0c\_i=0.
  • c=not,ac = \mathrm{ not }\\, a. Here, c_i=1c\_i=1 if a_ia\_i is equal to 00. Otherwise, c_i=0c\_i=0.

You are given an array of bitsets s_1,s_2,…,s_ns\_1, s\_2, \ldots, s\_n. Write a program that can answer kk queries of the following form:

  1. Take two integers ℓ\ell and rr.
  2. Find bitset tt using the formula: t=(s_ℓ,and,s_ℓ+1,and,…,and,s_r),xor,(not,(s_ℓ,or,s_ℓ+1,or,…,or,s_r))t = (s\_\ell \\,\mathrm{ and }\\, s\_{\ell+1} \\,\mathrm{ and }\\, \ldots \\,\mathrm{ and }\\, s\_r) \\,\mathrm{ xor }\\, (\mathrm{ not }\\, (s\_\ell \\,\mathrm{ or }\\, s\_{\ell+1} \\,\mathrm{ or }\\, \ldots \\,\mathrm{ or }\\, s\_r)).
  3. Count the number of ones in bitset tt: it is the answer.

입력

The first line contains two integers nn and mm (1≤n,m≤1051 \leq n, m \leq 10^5; n⋅m≤106n \cdot m \leq 10^6). The following nn lines describe the nn bitsets, where each line consists of mm characters 00 and 11 representing the bits of that bitset.

The next line of the input contains a single integer kk (1≤k≤2⋅1071 \leq k \leq 2 \cdot 10^7), which denotes the number of queries. The following line contains three integers xx, yy, and zz (1≤x,y,z≤1091 \leq x, y, z \leq 10^9).

The queries are generated using pseudo-random numbers, with input parameters xx, yy, and zz, and a sequence q_1,q_2,…,q_k−1q\_1, q\_2, \ldots, q\_{k - 1} of answers to the queries. Define two sequences aa and bb as follows:

  • a_1=1a\_1 = 1.
  • b_1=nb\_1 = n.
  • For i>1i > 1, a_i=(a_i−1⋅x+q_i−1⋅y+z) mod n+1a\_i = (a\_{i-1} \cdot x + q\_{i-1} \cdot y + z) \bmod n + 1.
  • For i>1i > 1, b_i=(b_i−1⋅y+q_i−1⋅z+x) mod n+1b\_i = (b\_{i-1} \cdot y + q\_{i-1} \cdot z + x) \bmod n + 1.

For each query ii, the parameters ℓ\ell and rr are defined as ℓ=min⁡(a_i,b_i)\ell=\min(a\_i, b\_i) and r=max⁡(a_i,b_i)r=\max(a\_i, b\_i).

출력

Output a single integer: the sum of the answers for all queries.

힌트

The queries are listed below:

#ℓ\ellrranswer
1114411
2334433
3224422
4113333

예제1

  1. 예제 1

    입력
    4 10
    1010110101
    0101111001
    1101101101
    1011010000
    4
    10 5 4
    
    예상 출력
    9