#P10264. [GESP202403 八级] 接竹竿
[GESP202403 八级] 接竹竿
Background
Related multiple-choice and true/false problems: https://ti.luogu.com.cn/problemset/1148.
Problem Description
Student Xiao Yang wants to play a card game called “Connecting Bamboo Poles”.
The rules are as follows: each card has a value . The given cards are placed one by one at the end of a queue of cards. If, before placing a card, there is already a card in the queue with the same value as this card, then Xiao Yang will remove from the queue all cards between these two cards (including the two cards themselves).
Xiao Yang now has a card sequence of length , where the value of each card is (). Xiao Yang has queries. In the -th query (), Xiao Yang gives . Xiao Yang wants to know: if we play “Connecting Bamboo Poles” using all cards with indices in in increasing index order, how many cards remain in the queue at the end.
Input Format
One line contains a positive integer , the number of test cases.
For each test case, the first line contains a positive integer , the length of the card sequence .
The second line contains positive integers , the values of the cards in .
The third line contains a positive integer , the number of queries.
The next lines each contain two positive integers , describing a query.
Output Format
For each test case, output lines. The -th line () outputs a non-negative integer, which is the answer to the -th query.
1
6
1 2 2 3 1 3
4
1 3
1 6
1 5
5 6
1
1
0
2
Hint
Sample Explanation
For the first query, Xiao Yang places the cards in the order . When placing the last card, the two cards with value are removed, so only one card with value remains in the queue.
For the second query, the queue changes as follows:
$\{\}\to\{1\}\to\{1,2\}\to\{1,2,2\}\to\{1\}\to\{1,3\}\to\{1,3,1\}\to\{\}\to\{3\}$. Therefore, in the end only one card with value remains in the queue.
Constraints
| Subtask | Score | Special Condition | ||||
|---|---|---|---|---|---|---|
| For all queries, the right endpoint equals . | ||||||
For all testdata, it is guaranteed that , , , and .
Translated by ChatGPT 5