CF1681B.Card Trick

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Monocarp has just learned a new card trick, and can't wait to present it to you. He shows you the entire deck of nn cards. You see that the values of cards from the topmost to the bottommost are integers a1,a2,…,ana_1, a_2, \dots, a_n, and all values are different.

Then he asks you to shuffle the deck mm times. With the jj-th shuffle, you should take bjb_j topmost cards and move them under the remaining (n−bj)(n - b_j) cards without changing the order.

And then, using some magic, Monocarp tells you the topmost card of the deck. However, you are not really buying that magic. You tell him that you know the topmost card yourself. Can you surprise Monocarp and tell him the topmost card before he shows it?

Monocarp 刚刚学会了一个新的纸牌魔术,迫不及待地想向你展示。他向你展示了整副包含 nn 张牌的牌堆。你看到这些牌从最上方到最下方的数值依次为整数 a1,a2,…,ana_1, a_2, \dots, a_n,且所有数值互不相同。

接着,他请你将这副牌洗牌 mm 次。在第 jj 次洗牌时,你需要取最上方的 bjb_j 张牌,并将它们以原有顺序置于剩余的 (n−bj)(n - b_j) 张牌的下方。

然后,Monocarp 运用某种“魔法”,告诉你此时牌堆最上方的牌是什么。然而,你并不真的相信这种“魔法”。你告诉他:你自己已经知道最上方的牌是什么了。你能否令 Monocarp 惊讶——在他揭晓之前,就准确说出最上方的牌?

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of testcases.

The first line of each testcase contains a single integer nn (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5) — the number of cards in the deck.

The second line contains nn pairwise distinct integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤n1 \le a_i \le n) — the values of the cards.

The third line contains a single integer mm (1≤m≤2⋅1051 \le m \le 2 \cdot 10^5) — the number of shuffles.

The fourth line contains mm integers b1,b2,…,bmb_1, b_2, \dots, b_m (1≤bj≤n−11 \le b_j \le n - 1) — the amount of cards that are moved on the jj-th shuffle.

The sum of nn over all testcases doesn't exceed 2⋅1052 \cdot 10^5. The sum of mm over all testcases doesn't exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试用例的数量。

每个测试用例的第一行包含一个整数 nn(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5)—— 牌组中牌的数量。

每个测试用例的第二行包含 nn 个两两不同的整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤n1 \le a_i \le n)—— 各张牌的数值。

每个测试用例的第三行包含一个整数 mm(1≤m≤2⋅1051 \le m \le 2 \cdot 10^5)—— 洗牌次数。

每个测试用例的第四行包含 mm 个整数 b1,b2,…,bmb_1, b_2, \dots, b_m(1≤bj≤n−11 \le b_j \le n - 1)—— 第 jj 次洗牌时被移动的牌的数量。

所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5;所有测试用例的 mm 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each testcase, print a single integer — the value of the card on the top of the deck after the deck is shuffled mm times.

对于每个测试用例,输出一个整数——即牌组经过 mm 次洗牌后位于牌组顶部的牌的数值。

输入输出样例

  • 输入#1

    3
    2
    1 2
    3
    1 1 1
    4
    3 1 4 2
    2
    3 1
    5
    2 1 5 4 3
    5
    3 2 1 2 1

    输出#1

    2
    3
    3

说明/提示

In the first testcase, each shuffle effectively swaps two cards. After three swaps, the deck will be [2,1][2, 1].

In the second testcase, the second shuffle cancels what the first shuffle did. First, three topmost cards went underneath the last card, then that card went back below the remaining three cards. So the deck remained unchanged from the initial one — the topmost card has value 33.

在第一个测试用例中,每次洗牌实际上交换了两张牌。经过三次交换后,牌组将变为 [2,1][2, 1]。

在第二个测试用例中,第二次洗牌抵消了第一次洗牌的效果。首先,最上面的三张牌被移到了最后一张牌的下方;接着,这张牌又回到了剩余三张牌的下方。因此,牌组与初始状态完全相同——最上面的牌的值为 33。

输入解题思路,AI测评打分。不知道怎么写?

首页