#P10150. [Ynoi1999] TS-54

[Ynoi1999] TS-54

Background

Problem Description

Given an integer sequence a1,,ana_1,\dots,a_n, it is guaranteed that there do not exist 1i<j<k<ln1 \le i < j < k < l \le n such that ai=aj=ak=ala_i = a_j = a_k = a_l.

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 values kk satisfy that there exist 1ix<jn1 \le i \le x < j \le n such that ai=aj=ka_i = a_j = k.

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 one operation.

Output Format

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

6 5
4 2 5 5 4 4
2
5
5
3
6
1
1
1
2
0

Hint

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

For 100%100\% of the testdata, all values are integers, 1ain1 \le a_i \le n, 1xn1 \le x \le n, and n,m5×105n,m \le 5 \times 10^5.

Translated by ChatGPT 5