#P8419. [THUPC 2022 决赛] riapq
[THUPC 2022 决赛] riapq
Problem Description
Given a permutation , you need to maintain a sequence , with initial values all equal to .
There are operations in total:
- Update operation: given , for every pair satisfying , increase by .
- Query operation: given , query .
Input Format
The first line contains two integers .
The second line contains integers representing in order.
The next lines each contain either or , representing an update operation or a query operation.
All numbers in the input are integers.
Output Format
For each query operation, output one line containing one integer, representing the answer.
8 10
5 4 8 7 1 6 3 2
1 2 5
2 8
1 2 8
1 7 8
2 4
2 1
2 6
2 4
1 8 8
2 4
0
4
0
3
4
4
Hint
Constraints:
.
, and all are pairwise distinct.
.
.
Translated by ChatGPT 5