QOJ.ac

QOJ

実行時間制限: 3.0 s メモリ制限: 1024 MB 満点: 100 ハック可能 ✓

#16229. 网格路径树

統計

给定正整数 $N$ 和 $M$。

对于每个 $k = 1, 2, \dots, N + M - 1$,令 $\text{ans}_k$ 表示以下问题的答案。

如果满足以下所有条件,则称长度均为 $N + M - 1$ 的双序列对 $(a, b)$(其中 $a = (a_1, a_2, \dots, a_{N+M-1})$ 且 $b = (b_1, b_2, \dots, b_{N+M-1})$)为好的序列对

  • $(a_1, b_1) = (1, N + 1)$
  • 对于 $i = 2, 3, \dots, N + M - 1$,以下条件之一成立:
    • $(a_i, b_i) = (a_{i-1} + 1, b_{i-1})$
    • $(a_i, b_i) = (a_{i-1}, b_{i-1} + 1)$
  • $(a_{N+M-1}, b_{N+M-1}) = (N, N + M)$

对于一个好的序列对 $(a, b)$,定义一棵树 $T(a, b)$ 如下:

  • 它是一棵拥有 $N + M$ 个顶点的树,顶点编号为 $1$ 到 $N + M$。
  • 对于每个 $i = 1, 2, \dots, N + M - 1$,存在一条连接顶点 $a_i$ 和顶点 $b_i$ 的边。

对于一棵树,令 $\text{dist}(i, j)$ 表示顶点 $i$ 和 $j$ 之间简单路径上的边数。该树的分数定义为满足 $1 \le i < j \le N + M$ 且 $\text{dist}(i, j) = k$ 的整数对 $(i, j)$ 的数量。

求出对于所有好的序列对 $(a, b)$,$T(a, b)$ 的分数之和,模 $998244353$ 的值。

计算所有值 $\text{ans}_1, \text{ans}_2, \dots, \text{ans}_{N+M-1}$,并输出 $\sum_{k=1}^{N+M-1} (\text{ans}_k \oplus k)$,其中 $\oplus$ 表示按位异或(XOR)。

输入格式

输入按以下格式给出:

N M

数据范围

  • $1 \le N \le 5 \times 10^6$
  • $1 \le M \le 5 \times 10^6$
  • 所有输入值均为整数。

输出格式

输出答案。

样例

输入样例 1

2 2

输出样例 1

14

输入样例 2

24 167

输出样例 2

21925979855

输入样例 3

4297614 4167924

输出样例 3

4162418864110099

说明

在第一个样例中,$(\text{ans}_1, \text{ans}_2, \text{ans}_3) = (6, 4, 2)$。因此,输出的值为 $(6 \oplus 1) + (4 \oplus 2) + (2 \oplus 3) = 7 + 6 + 1 = 14$。

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.