#P9366. [ICPC2022 Xi'an R] Square Grid

[ICPC2022 Xi'an R] Square Grid

题目描述

Given a square grid, its lattice points labeled from (0,0)(0, 0) to (n,n)(n, n), and a number tt.

You need to answer qq queries in this format: given A=(x0,y0)A = (x_0, y_0) and B=(x1,y1)B = (x_1, y_1), how many ways are there to move from AA to BB in exactly tt steps so that in each step you move from a lattice point to one of its neighbors (up, down, left, right). Calculate the answer modulo 998244353998\,244\,353.

输入格式

The first line contains three integers nn (1n1051 \leq n \leq 10^5), tt (1t1091 \leq t \leq 10^9) and qq (1q3×1051 \leq q \leq 3 \times 10^5).

Each of the following qq lines contains four integers x0x_0, y0y_0, x1x_1 and y1y_1 (0x0,y0,x1,y1n0 \leq x_0, y_0, x_1, y_1 \leq n), representing a query.

输出格式

For each query, output a line containing one integer, representing the answer to the query modulo 998244353998\,244\,353.

题目大意

给定正方形网格,格点坐标从 (0,0)(0,0)(n,n)(n,n)

qq 组询问,每次询问从 (x0,y0)(x_0, y_0) 走恰好 tt 步,每步只能朝上、下、左、右走一格,不走出边界,走到 (x1,y1)(x_1, y_1) 的方案数,对 998244353998\,244\,353 取模。所有询问的 tt 相同。

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

30
64
0

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

615136704
443203969
899931333
464755094
679729107

提示

Source: The 2022 ICPC Asia Xi'an Regional Contest Problem I.

Author: djq_cpp.