#P5673. 「SWTR-2」Picking Gifts
「SWTR-2」Picking Gifts
Description
There are many items in the shop. Each item has:
-
An index, from left to right as .
-
A category, as .
-
A value, as .
wants to choose an interval and buy all gifts in this interval to give to little .
Little will check the gifts from right to left. If she sees that gifts of the same category have appeared times, then she will not check this category anymore (including the -th one). Of course, those gifts will then lose their original value.
Now, gives you intervals and wants you to compute, in little 's view, the value of each interval.
See the sample for the detailed value calculation.
Input Format
The first line contains three positive integers separated by spaces.
The second line contains positive integers separated by spaces, where the -th number represents .
The third line contains positive integers separated by spaces, where the -th number represents .
The next lines each contain two positive integers , representing the interval of the -th query.
Output Format
Output lines. For each query, output one integer in one line, the value of this interval in little 's view.
6 11 3
1 1 1 2 1 3
7 3 8 9 6 5
1 1
1 2
1 3
1 4
1 5
1 6
2 6
3 6
4 6
5 6
6 6
7
10
11
20
23
28
28
28
20
11
5
Hint
Sample Explanation
.
.
, because the category of the gift with index is , and this is the -th time category appears, so she will not check this category anymore (including this one).
.
.
.
Constraints and Notes
Testdata : .
Testdata : .
Testdata : .
Testdata : .
Testdata : .
For testdata , . For the other testdata, .
For all testdata, $1\leq p_i\leq n,1\leq v_i\leq 2000,1\leq l \leq r \leq n$.
For testdata , each is worth points.
For testdata where , each is worth points.
All other testdata are worth points each.
For testdata , the time limit is .
For testdata , the time limit is .
For testdata , the time limit is .
Of course, the setters of SWTR-02 cannot possibly have girlfriends.
Translated by ChatGPT 5
京公网安备 11011102002149号