#P10181. 龙逐千灯幻

    ID: 11484 远端评测题 1200ms 128MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>线段树并查集洛谷原创O2优化凸完全单调性(wqs 二分)洛谷月赛根号分治单调栈

龙逐千灯幻

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 nn dragon lanterns. The color of the ii-th lantern is aia_i.

Fanfan defines the beauty value f(l,r)f(l,r) of an interval [l,r][l,r] as the number of distinct colors in alara_l \cdots a_r.

Fanfan is going out to have fun with his dragon lanterns. He plans to go out for mm days. On day ii, he will bring lanterns No. 1xi1 \cdots x_i. 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 xix_i lanterns, in order of their indices, into exactly kik_i 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 n,m,id,seed,limxn,m,id,seed,limx, representing the sequence length, the number of queries, the subtask\texttt{subtask} id (in the samples, id=0id=0), the random seed, and a parameter limxlimx 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 [l,r][l,r].

The second line contains nn integers, where the ii-th integer represents aia_i.

Let xi,ki,cix_i,k_i,c_i be the parameters x,k,cx,k,c needed for the ii-th query, where the role of cc 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 6464-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 ii-th query is ansians_i, and its generation parameter is cic_i, then you need to output:

i=1m(ansi×ci)\bigoplus\limits_{i=1}^m(ans_i\times c_i)

where \bigoplus 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 [1,3][1,3], and the beauty value is f(1,3)=3f(1,3)=3.

For the second query, the optimal plan is to divide into [1,3],[4,4],[5,5][1,3],[4,4],[5,5], and the beauty value is f(1,3)+f(4,4)+f(5,5)=5f(1,3)+f(4,4)+f(5,5)=5.

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 (1010 points): 1n5001 \leq n\leq 500.
  • Subtask 2 (1515 points): 1n30001\leq n\leq 3000.
  • Subtask 3 (1515 points): m=1m=1.
  • Subtask 4 (2020 points): 1ai301\le a_i\le 30.
  • Subtask 5 (2020 points): 1n4×1041\leq n\leq 4\times 10^4.
  • Subtask 6 (2020 points): No special restrictions.

For 100%100\% of the testdata, 1n1051 \leq n\leq 10^5, 1m1061\leq m\leq 10^6, 0seed1090\leq seed\leq 10^9, 1limxn1\leq limx\leq n, 1ain1\leq a_i\leq n

Translated by ChatGPT 5