#P2791. 幼儿园篮球题

    ID: 6090 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>数学2019O2优化组合数学快速数论变换 NTT

幼儿园篮球题

Background

As everyone knows, Cai Xukun, who “debuted” from the national talent show and has been in kindergarten for two and a half years, likes singing, dancing, rap, and basketball. As Irving’s teacher, his basketball skills are naturally much better than those of the “ikun” fans.

Problem Description

On Cai Xukun’s exclusive basketball court in the “national talent show kindergarten”, there are a total of NN exclusive basketballs, among which MM are deflated. Due to Cai Xukun’s superb skills, when he shoots a deflated ball, it must go in, and when he shoots an inflated ball, it must not go in.

Cai Xukun holds SS touring basketball performances. In the ii-th performance, the ikun fans specify the number of shots kik_i. They will prepare nin_i balls from the NN exclusive basketballs and place them on the court, among which exactly mim_i are deflated. Cai Xukun will randomly choose kik_i balls from these nin_i exclusive basketballs to shoot. If he makes xx shots, then the failure score of this performance is xLx^L. The ikun fans want to know, for these SS performances, the result of the expected failure score modulo 998244353998244353. The basketball performances are independent of each other.

Input Format

The first line contains four positive integers N,M,S,LN, M, S, L, representing the total number of Cai Xukun’s exclusive basketballs, the total number of deflated basketballs, the number of touring basketball performances, and the failure score parameter.

Each of the next SS lines contains three positive integers ni,mi,kin_i, m_i, k_i, representing, for the ii-th performance, the number of exclusive basketballs used, the number of deflated basketballs among them, and the number of shots specified by the ikun fans.

Output Format

Output SS lines in total. The ii-th line contains a positive integer, representing the expected failure score of the ii-th performance modulo 998244353998244353.

3 2 1 3
3 2 2
332748121

Hint

For the sample, we explain as follows. Let the failure score be XX. Cai Xukun has probability 13\frac{1}{3} to make 22 shots, and probability 23\frac{2}{3} to make 11 shot. The expected failure score is E(x)=233+1323=103E(x)=\frac{2^3}{3}+\frac{1^3*2}{3}=\frac{10}{3}, and 103332748121(mod998244353)\frac{10}{3}\equiv 332748121\pmod{998244353}.

Subtask 1 (15%15\%): 1L21\leq L\leq2.

Subtask 2 (10%10\%): 1N1051\leq N\leq10^5.

Subtask 3 (75%75\%): No special constraints.

For all testdata, 1S2001\leq S\leq200, 1L2×1051\leq L\leq2\times 10^5, 1MN2×1071\leq M\leq N\leq2\times 10^7. Also, for 1iS1\leq i\leq S, we have 1mi,kiniN1\leq m_i,k_i\leq n_i\leq N, 1miM1\leq m_i\leq M.

Translated by ChatGPT 5