#P6604. [HNOI2016] 序列 加强版

[HNOI2016] 序列 加强版

Description

Given a sequence of length nn: a1,a2,,ana_1, a_2, \cdots, a_n, denoted as a[1 ⁣:n]a[1 \colon n]. Similarly, a[l ⁣:r]a[l \colon r] (1lrn1 \leq l \leq r \leq n) refers to the sequence al,al+1,,ar1,ara_l, a_{l+1}, \cdots, a_{r-1}, a_r. If 1lstrn1 \leq l \leq s \leq t \leq r \leq n, then a[s ⁣:t]a[s \colon t] is called a subsequence of a[l ⁣:r]a[l \colon r].

Now there are qq queries. Each query gives two numbers ll and rr, 1lrn1 \leq l \leq r \leq n. For each query, find the sum of the minimum values of all distinct subsequences of a[l ⁣:r]a[l \colon r]. For example, given the sequence 5,2,4,1,35, 2, 4, 1, 3, and a query with l=1l = 1 and r=3r = 3, then a[1 ⁣:3]a[1 \colon 3] has 66 subsequences: a[1 ⁣:1]a[1 \colon 1], a[2 ⁣:2]a[2 \colon 2], a[3 ⁣:3]a[3 \colon 3], a[1 ⁣:2]a[1 \colon 2], a[2 ⁣:3]a[2 \colon 3], a[1 ⁣:3]a[1 \colon 3]. The sum of the minimum values of these 66 subsequences is 5+2+4+2+2+2=175 + 2 + 4 + 2 + 2 + 2 = 17.

Input Format

The first line contains three integers nn, qq, typetype, representing the sequence length, the number of queries, and the input method.

The second line contains nn integers describing the sequence.

If type=0type = 0, then the next qq lines each contain two numbers ll and rr, representing the query interval [l,r][l, r].

If type=1type = 1, then the data is generated by the following code:

namespace gen{
	typedef unsigned long long ull;
	ull s,a,b,c,lastans=0;
	ull rand(){
		return s^=(a+b*lastans)%c;
	}
};

The initial values of s, a, b, c are given on the third line, where s, a, b are all in [0,109][0, 10^9], and c is in [1,109][1, 10^9]. lastans is the value of the previous query answer converted to type unsigned long long, and for the first query it is 00.

For each query, you can generate ll and rr in the following way:

l=gen::rand()%n+1;
r=gen::rand()%n+1;
if(l>r) std::swap(l,r);

Output Format

Output one integer in a single line, which is the XOR sum of the answers of all queries after converting each answer to type unsigned long long.

5 5 0
5 2 4 1 3
1 5
1 3
2 4
3 5
2 5

28

6 5 1
1 1 4 5 1 4
19 19 8 10

6

Hint

  • For 30%30\% of the data, 1q1051 \leq q \leq 10^5, type=0type = 0.
  • For the other 70%70\% of the data, 1q1071 \leq q \leq 10^7, type=1type = 1.

Constraints: for 100%100\% of the data, 1n1051 \leq n \leq 10^5, 109ai109-10^9 \leq a_i \leq 10^9.

Translated by ChatGPT 5