#P10028. [Ynoi2000] pri

[Ynoi2000] pri

Problem Description

Given a permutation a1,a2,,ana_1, a_2, \dots, a_n of 1,,n1, \dots, n.

There are mm operations. In each operation, an integer xx is given. First, perform a modification: reverse a1,a2,,axa_1, a_2, \dots, a_x into ax,,a2,a1a_x, \dots, a_2, a_1. Then query how many distinct pairs (i,j)(i, j) satisfy 1i<jx1 \le i < j \le x and ai<aja_i < a_j.

Input Format

The first line contains two integers n,mn, m.

The second line contains nn integers representing a1,,ana_1, \dots, a_n in order.

The next mm lines each contain one integer xx, representing an operation.

Output Format

Output mm lines. Each line contains one integer, representing the answer to the query for each operation in order.

6 5
5 4 2 3 1 6
3
5
6
3
6
3
6
4
2
10

Hint

Idea: ccz181078, Solution: ccz181078, Code: ccz181078, Data: ccz181078.

All values are integers.

Constraints: for 100%100\% of the testdata, 1ain1 \le a_i \le n, 1xn1 \le x \le n, 1n2×1051 \le n \le 2 \times 10^5, 1m5×1041 \le m \le 5 \times 10^4.

Translated by ChatGPT 5