#P9639. 「yyOI R1」youyou 的序列

「yyOI R1」youyou 的序列

Problem Description

You are given a sequence a1na_{1\dots n} of length nn, and qq operations.

One operation is defined as: swap the values of aka_k and ak+1a_{k+1}, and immediately ask for the sum of the numbers of subsequences that have ai  (i[1,n])a_i \;( i\in [1,n]) as the peak, modulo 42949672964294967296. This swap is temporary, meaning it is only valid until the next operation.

Here we consider that a sequence of length at least 11, $[a_1,a_2,\cdots,a_{s-1},a_s,a_{s+1},\cdots,a_{n-1},a_n]$, is called a sequence with peak at asa_s if it satisfies $a_1<a_2<\cdots<a_{s-1}<a_s>a_{s+1}>\cdots>a_{n-1}>a_n$.

Your task is to output the answer for every operation.

Input Format

The first line contains two integers n,qn,q.

The second line contains nn positive integers, the initial sequence a1na_{1\dots n}.

The third line contains an integer kk, meaning the first operation (as defined above) is performed, and it is guaranteed that 1k<n1\le k < n.


For operations 22 to qq, the value of kk is obtained as follows:

int Answer(unsigned int ans)
{
    unsigned int BASE=998244353ll*ans+ans*ans+ans/9991+ans%2159;
    BASE^=9810;
    BASE^=51971;
    BASE=BASE>>7;
    BASE=BASE<<11;
    BASE^=751669;
    BASE^=23465695622566ll;
    return BASE%(n-1)+1;
}

After you finish each query, use the answer of this query ansans as the parameter and call Answer(ans) exactly once.

The return value is the kk for the next operation.

Note: This input method is only used to reduce the input size. The standard solution does not rely on this input method.

Output Format

Output the answers for all operations, one per line.

4 3
1 5 7 3
1

12
13
13

5 5
7 7 7 7 6
1
9
9
9
9
9

Hint

Sample Explanation #1

For the first operation, kk is 11.

Now the sequence is [5,1,7,3][5,1,7,3].

Peak at a1a_1: [5][5], [5,1][5,1], [5,3][5,3].

Peak at a2a_2: [1][1].

Peak at a3a_3: [7][7], [5,7][5,7], [1,7][1,7], [7,3][7,3], [5,7,3][5,7,3], [1,7,3][1,7,3].

Peak at a4a_4: [3][3], [1,3][1,3].

In total there are 1212 different subsequences, so the answer is 1212.

For the second and third operations, kk is both 33. At this time there are 1313 different sequences that satisfy the condition.

Sample Explanation #2

For the first operation, kk is 11.

Now the sequence is [7,7,7,7,6][7,7,7,7,6].

Peak at a1a_1: [7][7], [7,6][7,6].

Peak at a2a_2: [7][7], [7,6][7,6].

Peak at a3a_3: [7][7], [7,6][7,6].

Peak at a4a_4: [7][7], [7,6][7,6].

Peak at a5a_5: [6][6].

In total there are 99 different subsequences, so the answer is 99.

The last four operations are similar.


Constraints

This problem uses bundled testdata.

Subtask ID nn qq Score
11 500\le 500 100\le 100 1010
22 2×103\le2\times10^3 5×103 \le 5\times10^3 2020
33 3×104\le3\times10^4 104\le 10^4 3030
44 106\le10^6 106 \le10^6 4040

For 100%100\% of the testdata, 2n1062\le n\le10^6, 1q1061\le q\le10^6, 1ai1041\le a_i\le10^4.

Translated by ChatGPT 5