Minimize Inversion

AtCoder
IDarc213_d
Time2000ms
Memory256MB
Difficulty
You are given positive integers $N$ and $K$ satisfying $1\leq K\leq N$. For a permutation $P = (P_{1}, P_{2}, \dots , P_{N})$ of $(1, 2, \dots , N)$, define $f(P)$ as follows: * The minimum possible value of the number of inversions of a length-$N$ integer sequence $A = (A_{1}, A_{2}, \dots, A_{N})$ satisfying the following condition: * $|A_{i}| = P_{i}$ for every integer $1\leq i\leq N$. For $a = 1, 2, \dots, N$, answer the following question: > There are $(N - 1)!$ permutations $P = (P_{1}, P_{2}, \dots , P_{N})$ of $(1, 2, \dots , N)$ satisfying $P_{K} = a$. Find the sum, modulo $998244353$, of $f(P)$ over all of them. ## Constraints * $1\leq K\leq N\leq 2\times 10^{5}$ * All input values are integers. ## Input The input is given from Standard Input in the following format: $N$ $K$ [samples]
Samples
Input #1
4 2
Output #1
3
3
6
8
Input #2
1 1
Output #2
0
Input #3
16 7
Output #3
262718137
262718137
826158422
869037161
443336358
897729892
154945392
124681723
861272045
3176021
900143166
451899023
365015181
740245202
732524873
391198612
API Response (JSON)
{
  "problem": {
    "name": "Minimize Inversion",
    "description": {
      "content": "You are given positive integers $N$ and $K$ satisfying $1\\leq K\\leq N$. For a permutation $P = (P_{1}, P_{2}, \\dots , P_{N})$ of $(1, 2, \\dots , N)$, define $f(P)$ as follows: *   The minimum possibl",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc213_d"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given positive integers $N$ and $K$ satisfying $1\\leq K\\leq N$.\nFor a permutation $P = (P_{1}, P_{2}, \\dots , P_{N})$ of $(1, 2, \\dots , N)$, define $f(P)$ as follows:\n\n*   The minimum possibl...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments