Digit DP

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

요약
부분집합 합으로 정의된 0부터 2^n-1까지의 배열에서 구간 덧셈과 세 원소 곱의 합을 구하는 구간 질의를 처리한다.
난이도

어려움10점 중 8점

유형
세그먼트 트리, 분할 정복, 수학, 행렬
정답자
아직 제출이 없습니다

문제

There are 2n2^n machines in a factory, numbered from 00 to 2n−12^n-1. The ii-th machine consumes p_ip\_i units of power. The factory uses a system called Digit Dynamic Powering (Digit DP) to control the power the machines consume.

Initially, an array a_0,…,a_n−1a\_0, \ldots, a\_{n-1} is given. Then the system would set the initial p_ip\_i to ∑_j∈S_ia_j\sum\limits\_{j \in S\_i}{a\_j}, where S_iS\_i is the set of 11 bits in the binary representation of ii.

After that, there may be some modifications, each modification would be adding a certain value to the power of some machines that form an interval. Formally speaking, you would be given three integers ℓ\ell, rr, xx, meaning that the power consumed by each of the machines numbered between ℓ\ell and rr (inclusively) should increase by xx. The endpoints of the intervals would be given as nn-digit binary strings.

When some three distinct machines are used to produce a product, the product's price should always be the product of the p_ip\_i's of those machines.

During these modifications, the manager may ask some questions about some intervals. What is the sum of the prices if we try every possible combination of three distinct machines in the interval to produce a product?

Formally speaking, you would be given two integers ℓ\ell, rr, meaning that you should report the sum of the products p_i⋅p_j⋅p_kp\_i \cdot p\_j \cdot p\_k of all triples (i,j,k)(i,j,k) satisfying ℓ≤i<j<k≤r\ell \leq i < j < k \leq r. As the answer may be rather large, find it modulo 998,244,353998\\,244\\,353. The endpoints of the intervals would also be given as nn-digit binary strings.

입력

The first line contains two integers nn and qq (1≤n≤1001 \leq n \leq 100; 1≤q≤5⋅1041 \leq q \leq 5 \cdot 10^4).

The second line contains the integer array a_0,a_1,…,a_n−1a\_0, a\_1, \ldots, a\_{n-1} (0≤a_i≤1090 \leq a\_i \leq 10^9).

The next qq lines contain queries. On each line, the first integer tt indicates the type of the query.

If t=1t = 1, three integers ℓ\ell, rr, xx follow (0≤ℓ≤r<2n0 \leq \ell \leq r < 2^n, 0≤x≤1090 \leq x \leq 10^9).

If t=2t = 2, two integers ℓ\ell, rr follow (0≤ℓ≤r<2n0 \leq \ell \leq r < 2^n).

Note that ℓ\ell and rr are given in nn-bit binary string format, and the leftmost bit is the highest bit.

출력

For each query of type 22, print a line with a single integer: the answer modulo 998,244,353998\\,244\\,353.

예제2

  1. 예제 1

    입력
    3 3
    1 2 4
    2 000 111
    1 010 101 1
    2 000 111
    
    예상 출력
    1960
    3040
    
  2. 예제 2

    입력
    2 2
    1 1
    2 00 10
    2 00 11
    
    예상 출력
    0
    2