#P9639. 「yyOI R1」youyou 的序列
「yyOI R1」youyou 的序列
Problem Description
You are given a sequence of length , and operations.
One operation is defined as: swap the values of and , and immediately ask for the sum of the numbers of subsequences that have as the peak, modulo . This swap is temporary, meaning it is only valid until the next operation.
Here we consider that a sequence of length at least , $[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 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 .
The second line contains positive integers, the initial sequence .
The third line contains an integer , meaning the first operation (as defined above) is performed, and it is guaranteed that .
For operations to , the value of 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 as the parameter and call Answer(ans) exactly once.
The return value is the 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, is .
Now the sequence is .
Peak at : , , .
Peak at : .
Peak at : , , , , , .
Peak at : , .
In total there are different subsequences, so the answer is .
For the second and third operations, is both . At this time there are different sequences that satisfy the condition.
Sample Explanation #2
For the first operation, is .
Now the sequence is .
Peak at : , .
Peak at : , .
Peak at : , .
Peak at : , .
Peak at : .
In total there are different subsequences, so the answer is .
The last four operations are similar.
Constraints
This problem uses bundled testdata.
| Subtask ID | Score | ||
|---|---|---|---|
For of the testdata, , , .
Translated by ChatGPT 5