Convolution

시간 제한2초메모리 제한1024 MB

요약
n개 원소 집합의 모든 부분집합에 대한 값 f와 g가 주어질 때, B ∪ C = A인 모든 B, C에 대해 f(B)g(C)를 더한 부분집합 합성곱 h(A)를 구한 뒤 각 테스트 케이스마다 하나의 검증값을 출력한다.
난이도

어려움10점 중 8점

유형
동적 계획법, 조합론, 비트 연산, 수학
정답자
아직 제출이 없습니다

문제

Consider all subsets of set U=0,1,2,…,n−1U = \\{0, 1, 2, \dots, n-1\\}. Every subset A=a_1,a_2,…,a_kA = \\{a\_1, a\_2, \dots, a\_k\\} corresponds to a unique integer p(A)=∑_i=1k2a_ip(A) = \sum\limits\_{i=1}^k 2^{a\_i}. Let function FF of an nn-element set be defined by an array of integers ff of length 2n2^n: the value F(A)F(A) is equal to f\[p(A)]f\[p(A)].

You are given two functions FF and GG. Your task is to find such function HH that H(A)=∑_B∪C=AF(B)G(C).H(A) = \sum\limits\_{B \cup C = A}F(B)G(C)\text{.}

입력

The first line contains two integers nn and tt (1≤n≤161 \le n \le 16, 1≤t≤1001 \le t \le 100). Here, nn is the size of the set UU, and tt is number of test cases. The second line contains two integers aa and bb, each from 11 to 10910^9. These numbers are used in the following pseudo-random generator:

1. unsigned int cur = 0; // unsigned 32-bit integer
2. unsigned int nextRand16() {
3.   cur = cur * a + b; // calculated modulo 232
4.   return cur / 216; // integer from 0 to 216-1
5. }

The test cases are generated successively. In each of them, first, you must generate the elements of array ff (values of FF) in the order of increasing array index, and after that, you must generate the elements of gg (values of GG) in the same order. Each element is generated by calling the function nextRand16().

출력

For each test case, print one integer on a separate line: (∑_AH(A)⋅(p(A)+1)) mod 232.\left(\sum\limits\_A H(A) \cdot (p(A)+1)\right) \bmod 2^{32}\text{.}

힌트

The arrays in the first example are the following:

  • f_1 ⁣:3,113,3395,36331,41370,61471,9130,11774f\_1 \colon 3,113,3395,36331,41370,61471,9130,11774
  • g_1 ⁣:25547,45526,55066,13590,14501,41817,9356,18543g\_1 \colon 25547,45526,55066,13590,14501,41817,9356,18543
  • h_1 ⁣:76641,8167827,273846333,5284992017,1656829263,11450721456,3699971823,14260048942h\_1 \colon 76641,8167827,273846333,5284992017,1656829263,11450721456,3699971823,14260048942
  • f_2 ⁣:32024,43238,51978,52034,53714,38578,43250,52338f\_2 \colon 32024,43238,51978,52034,53714,38578,43250,52338
  • g_2 ⁣:62834,50034,59250,8050,44914,36722,53106,20338g\_2 \colon 62834,50034,59250,8050,44914,36722,53106,20338
  • h_2 ⁣:2012196016,6482475400,8243104152,15561662464,7225902008,16869349792,22350138288,44342816072h\_2 \colon 2012196016,6482475400,8243104152,15561662464,7225902008,16869349792,22350138288,44342816072

예제2

  1. 예제 1

    입력
    3 2
    30 239017
    
    예상 출력
    2723387430
    3167905008
    
  2. 예제 2

    입력
    16 2
    239 17
    
    예상 출력
    551267264
    1632349120