#P10181. 龙逐千灯幻
龙逐千灯幻
Background

The Year of the Dragon has arrived, and Fanfan has also raised his own colorful dragon lantern. He wants to become a big colorful dragon too.
Problem Description
Fanfan has a total of dragon lanterns. The color of the -th lantern is .
Fanfan defines the beauty value of an interval as the number of distinct colors in .
Fanfan is going out to have fun with his dragon lanterns. He plans to go out for days. On day , he will bring lanterns No. . However, he finds that if many lanterns are bundled together, others will only notice how many different colors there are.
So Fanfan plans to divide these lanterns, in order of their indices, into exactly intervals, such that each lantern belongs to exactly one interval.
Then the beauty value of this trip is the sum of the beauty values of all intervals.
Please help Fanfan maximize the beauty value for each trip.
Input Format
The first line contains five integers , representing the sequence length, the number of queries, the id (in the samples, ), the random seed, and a parameter related to the queries.
Because the input size is too large, the queries are generated in the following way.
We use the following code to generate a pseudo-random sequence:
uint64_t PRG_state;
uint64_t get_number()
{
PRG_state ^= PRG_state << 13;
PRG_state ^= PRG_state >> 7;
PRG_state ^= PRG_state << 17;
return PRG_state;
}
int readW(int l,int r)
{
return get_number()%(r-l+1)+l;
}
Initially, PRG_state=seed. Each time you call readW(l,r), it returns a random number within .
The second line contains integers, where the -th integer represents .
Let be the parameters needed for the -th query, where the role of is described in the output format. Then all query parameters can be generated by the following program:
for (int i = 1; i <= m; ++i) {
x[i] = readW(limx, n);
k[i] = readW(1, x[i]);
c[i] = readW(0, 1e7);
}
Note: Do not call readW() before running the code snippet above to obtain the parameters for each query, otherwise you will not get the correct query information. This problem does not require using any special property of this pseudo-random generator. You only need to treat get_number() as a generator that independently and uniformly produces an unsigned -bit integer each time it is called. This problem also does not require optimizing the internal implementation of the pseudo-random generator.
Output Format
To reduce the amount of output, we use the following compression method.
If the answer to the -th query is , and its generation parameter is , then you need to output:
where denotes the bitwise XOR operation. This value is guaranteed to be within the integer range representable by long long.
5 5 0 956144375 1
2 4 1 5 2
21971409
10 10 0 478178732 1
2 2 1 1 2 1 2 1 2 1
2834792
Hint
Sample 1 Explanation
The queries are:
3 1 6121576
5 3 3089509
1 1 4506170
3 1 2821007
1 1 7941511
The answers are:
3
5
1
3
1
For the first query, it must be divided into one interval, so it is , and the beauty value is .
For the second query, the optimal plan is to divide into , and the beauty value is .
The last three queries are similar.
Sample 2 Explanation
The queries are:
8 4 6858024
3 2 236530
2 2 8140891
5 3 4562139
8 7 4749403
7 4 4319971
5 1 5063575
3 1 7343109
6 2 1566851
3 1 7959241
The query answers are:
7
3
2
5
8
7
2
2
4
2
Constraints
This problem uses bundled testdata.
- Subtask 1 ( points): .
- Subtask 2 ( points): .
- Subtask 3 ( points): .
- Subtask 4 ( points): .
- Subtask 5 ( points): .
- Subtask 6 ( points): No special restrictions.
For of the testdata, , , , , 。
Translated by ChatGPT 5