#P8852. [JRKSJ R5] Concvssion

    ID: 9316 远端评测题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2022多项式洛谷原创O2优化树链剖分生成函数基环树洛谷月赛

[JRKSJ R5] Concvssion

Background

You really like Concvssion, but that does not stop you from doing an interesting problem that is not difficult.

(The background image is from the Phigros music illustration. If there is any infringement, please inform the problem setter.)

Problem Description

Given sequences a,ba, b of length nn, satisfying i[1,n],ai,bi[1,n]\forall i\in[1,n], a_i, b_i\in[1,n].

Define one operation as: i[1,n],biabi\forall i\in[1,n], b_i\gets a_{b_i}.

You need to perform nn operations in order. After each operation, output i=1nbimod998244353\displaystyle\sum_{i=1}^n b_i \bmod 998244353.

Input Format

The first line contains an integer nn.

The second line contains nn integers representing a1na_{1\sim n}.

The third line contains nn integers representing b1nb_{1\sim n}.

Output Format

Output nn lines. Each line contains one integer, the answer modulo 998244353998244353.

5
2 3 4 5 1
2 2 3 1 1
14
19
19
14
9
5
3 5 1 4 2
2 2 3 1 1
17
9
17
9
17
5
1 1 2 2 4
2 2 3 1 1
6
5
5
5
5
5
3 1 5 3 4
2 2 1 3 3
15
19
20
21
19

Hint

Idea: cyffff, Solution: Ntokisq / WhisperingSnowflakes, Code: cyffff / WhisperingSnowflakes, Data: cyffff.

Concvssion - Halv (Insane15.5)

Constraints

This problem uses bundled testdata.

::cute-table | Subtask\text{Subtask} | nn\le | Special Property | Score\text{Score} | | :----------: | :----------: | :----------: | :----------: | | 11 | 10410^4 | None | 1010 | | 22 | 10510^5 | i[1,n],ai103\forall i\in[1,n],a_i\le10^3 | 1010 | | 33 | ^ | i[1,n],ai=imodn+1\forall i\in[1,n],a_i=i\bmod n+1 | 1010 | | 44 | ^ | aa is a permutation of [1,n][1,n] | 1515 | | 55 | ^ | a1=1,i[2,n],ai<ia_1=1,\forall i\in[2,n],a_i< i | 2525 | | 66 | ^ | None | 2020 | | 77 | 3×1053\times10^5 | ^ | 1010 |

For 100%100\% of the testdata, 1ai,bin3×1051\le a_i,b_i\le n\le 3\times10^5.

Special Scoring Method

This problem uses subtask dependencies, as follows:

  • For subtask i{1,2,3,5}i\in\{1,2,3,5\}, you only need to solve subtask ii correctly to get the score for subtask ii.
  • For subtask i=4i=4, you need to solve all subtasks j[3,4]j\in[3,4] correctly to get the score for subtask ii.
  • For subtasks i{6,7}i\in\{6,7\}, you need to solve all subtasks j[1,i]j\in[1,i] correctly to get the score for subtask ii.

Translated by ChatGPT 5