#P9221. 「TAOI-1」Pentiment

    ID: 9837 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DP线段树颜色段均摊(珂朵莉树 ODT)O2优化

「TAOI-1」Pentiment

Background

Recently (dubious), a game called 闊靛緥婧愮偣 updated to version 4.0. In this version, a certain chart’s huge right-angle snake left a deep impression on the players...

Problem Description

We define the following in an nn-row, mm-column grid: a “right-angle snake” is a path with these rules:

  • It starts from the center of some cell in the bottommost row (row 11) and ends at the center of some cell in the topmost row (row nn).
  • Each move can go up, right, or left by one cell, and after each move it arrives at the center of a cell (moving down is not allowed).
  • It cannot pass through the same cell more than once.

In particular, to make it more challenging, some cells are forbidden for the “right-angle snake” to pass through.

Count how many such “right-angle snakes” exist in the given grid. Output the answer modulo 998244353998244353.

Input Format

The first line contains three integers n,m,qn, m, q, representing the number of rows, the number of columns, and the number of constraints.

The next qq lines each contain two integers xi,yix_i, y_i, meaning that the cell at row xix_i and column yiy_i cannot be passed through. It is guaranteed that each cell appears at most once. It is guaranteed that all cells are given in increasing order when sorted by xix_i as the primary key and yiy_i as the secondary key. (We define the bottommost row as row 11, and the leftmost column as column 11.)

Output Format

Output one integer: the number of valid “right-angle snakes” modulo 998244353998244353.

2 3 2
1 1
2 1
8
4 4 4
1 1
2 2
3 3
4 4
0
6 5 4
1 3
3 1
3 4
5 2
2000
100000000 100000000 0
103866487

Hint

Constraints

This problem uses bundled testdata.

  • Subtask 1 (10 points): n106n \leq 10^6, m2m \leq 2.
  • Subtask 2 (10 points): q=0q = 0.
  • Subtask 3 (15 points): n,m104n, m \leq 10^4.
  • Subtask 4 (20 points): n104n \leq 10^4.
  • Subtask 5 (20 points): m104m \leq 10^4.
  • Subtask 6 (25 points): no special restrictions.

For all testdata, 2n1092 \leq n \leq 10^9, 1m1091 \leq m \leq 10^9, 0q1050 \leq q \leq 10^5, 1xin1 \leq x_i \leq n, 1yim1 \leq y_i \leq m.

Sample Explanation

As shown in the figure, there are eight valid “right-angle snakes” in Sample 1.

For Sample 2, there are no valid “right-angle snakes”.


Surrender in ashes as cold as death.

Surrender amid drifting uncertainty.

Surrender at the last step, just short of success.

Translated by ChatGPT 5