#P7493. [传智杯 #3 决赛] 旅人1969

    ID: 8348 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP多项式O2优化快速数论变换 NTT传智杯

[传智杯 #3 决赛] 旅人1969

Background

In the 21st century, which is called the future, only unease and a little fantasy remain.

O sinners of eternity and instant, the Noah's Ark of the 20th century carries expectations and unease and flies toward the sky!

And you, as hope, on this journey that is not eternal, how will you move forward?

Problem Description

On a straight road, there are nn hotels. The coordinate of the ii-th hotel is ii. Every morning, you start from a hotel and can walk a maximum distance of mm. You are also given a fixed constant kk.

You are given qq queries. In each query, given u,vu, v, find the number of plans to start in the morning from hotel uu to hotel vv, passing through at most kk hotels (excluding the start point uu) and keeping the walking direction unchanged. Two plans are different if and only if there exists a different choice of a hotel. The answer should be taken modulo 998244353998244353.

For all testdata, n,q105n, q \leq 10^5, m,k104m, k \leq 10^4, mk105mk \leq 10^5, and u,vnu, v \leq n.

Input Format

The input has q+1q + 1 lines.

The first line contains 44 positive integers n,m,k,qn, m, k, q.

The next qq lines each contain 22 positive integers u,vu, v, representing a query.

Output Format

Output qq lines, each containing 11 integer, representing the answer.

3 2 2 2
1 3
2 3
2
1
2077 30 200 3
1949 2021
1969 2077
1970 2004

360658315
804081653
603979748

Hint

Translated by ChatGPT 5