QOJ.ac

QOJ

Límite de tiempo: 1.5 s Límite de memoria: 512 MB Puntuación total: 100

#4922. Living Below the Diagonal

Estadísticas

In a nutshell:

Given a bivariate polynomial $F(x, y)$ of degree $p \times q$, compute

$$\sum_{x = 0}^n \sum_{y = 0}^{\min(x, m)} \binom{x + y}{x} \binom{n - x + m - y}{n - x} F(x, y)$$

modulo $998244353$.

Each test case contains $T$ queries, and it is guaranteed that the value $m - n$ is a constant $c$ across all queries.

Input

The first line contains five integers $T, c, p, q, N$, representing the number of queries, the constant $m - n = c$, the degree of the bivariate polynomial, and the upper bound of $n$ for all queries in this test case, respectively (i.e., $n \leq N$ for all queries).

The next $T$ lines contain the test data, where each test case is provided as follows:

The first line contains two integers $n$ and $m$, guaranteed to satisfy $m - n = c$.

The next $p + 1$ lines each contain $q + 1$ integers, where the $j$-th number in the $i$-th line represents the coefficient of $x^{i - 1} y^{j - 1}$ in $F(x, y)$.

Output

Output $T$ lines, each containing an integer representing the answer to the problem.

Examples

Input 1

2 0 1 1 5
1 1 
1 1
1 1
2 2
1 2
3 4

Output 1

12
278

Constraints

For convenience, let $L = \max(N, N + c)$ be the range of coordinates in the queries.

For all test data: $1 \leq T \leq 10^5, -10^5 \leq c \leq 10^5, 1 \leq L \leq 10^5, 0 \leq (p + 1) \times (q + 1) \leq 10$. It is guaranteed that the coefficients of the input polynomial are in the range $[0, 998244353)$.

  • Subtask 1 ($1$ pts): $T = 1, L \leq 10^3$
  • Subtask 2 ($9$ pts): $L \leq 10^3$
  • Subtask 3 ($20$ pts): $T = 1, p = q = 0$
  • Subtask 4 ($20$ pts): $p = q = 0$
  • Subtask 5 ($20$ pts): $T = 1$
  • Subtask 6 ($10$ pts): $c = 0$
  • Subtask 7 ($20$ pts): No special constraints.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.