#C6763. Unique Subarray Sum
Unique Subarray Sum
Unique Subarray Sum
You are given an array of n integers and q queries. Each query consists of two indices l and r (1-indexed). For each query, you need to compute the sum of the subarray from index l to index r (i.e., \(\sum_{i=l}^{r} a_i\)). However, if any element appears more than once in the subarray, you should output \(-1\) for that query.
Input Constraints:
- 1 ≤ n, q ≤ 105 (depending on the version of the problem)
- 1 ≤ ai ≤ 109
- 1 ≤ l ≤ r ≤ n
Note: The indices in the queries are 1-indexed.
inputFormat
The input is read from standard input (stdin) with the following format:
- The first line contains two integers n and q, representing the number of elements in the array and the number of queries respectively.
- The second line contains n space-separated integers representing the array.
- Each of the next q lines contains two integers l and r representing the bounds of the query.
outputFormat
For each query, output a single line. The line should contain the sum of the elements from index l to r if all elements in the subarray are distinct; otherwise, output -1.
## sample6 3
1 2 3 3 2 1
1 3
4 6
2 5
6
6
-1
</p>