#P17473. [ICPC 2018 Jiaozuo R] Can You Solve the Harder Problem?
[ICPC 2018 Jiaozuo R] Can You Solve the Harder Problem?
题目描述
You are given a sequence denoted by . A query with is defined as
$$\displaystyle Q_{max}(l, r) = \max \lbrace a_l, a_{l + 1}, \cdots, a_r \rbrace .$$An easy problem may ask you to calculate the sum of answers for all queries with integers , but we would like to show you a harder one.
Define a classifier as a container that stores unique elements. Each element in the classifier has two values, named the key value and the mapped value. The key value of each element is a consecutive subsequence of and the mapped value of that element is an integer indicating the maximum value in the subsequence. The classifier only stores elements with distinct key values, which means extra duplicated elements (with the same key value) would be removed from the classifier.
Denote as , a consecutive subsequence of meeting the condition that and are integers with . Now we intend to use a classifier to store all the consecutive subsequences of with their . You are asked to determine the sum of mapped values in .
Actually, what we defined above is a map of the form map<vector<int>, int> in C++ or Map<ArrayList<Integer>, Integer> in Java, so if you are seasoned using these data structures, you may realize that what we intend to do is to insert all possible elements with integers into the classifier and then ask you to calculate the sum of mapped values in it.
输入格式
The input contains several test cases, and the first line contains a positive integer indicating the number of test cases which is up to .
For each test case, the first line contains an integer indicating the number length of the given sequence , where .
The second line contains positive integers describing the sequence , where .
We guarantee that there are at most test cases with .
输出格式
For each test case, output a line containing the sum of mapped values in .
2
3
1 2 3
3
2 3 3
14
14
提示
In the first sample case, the sum of mapped values in is equal to .
In the second sample case, the sum of mapped values in is equal to .