2022.5.23 codeforces B题

16 篇文章 0 订阅
2022.5.23 codeforces B题

Monocarp has just learned a new card trick, and can’t wait to present it to you. He shows you the entire deck of n cards. You see that the values of cards from the topmost to the bottommost are integers a1,a2,…,an, and all values are different.

Then he asks you to shuffle the deck m times. With the j-th shuffle, you should take bj topmost cards and move them under the remaining (n−bj) 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?

Input
The first line contains a single integer t (1≤t≤104) — the number of testcases.

The first line of each testcase contains a single integer n (2≤n≤2⋅105) — the number of cards in the deck.

The second line contains n pairwise distinct integers a1,a2,…,an (1≤ai≤n) — the values of the cards.

The third line contains a single integer m (1≤m≤2⋅105) — the number of shuffles.

The fourth line contains m integers b1,b2,…,bm (1≤bj≤n−1) — the amount of cards that are moved on the j-th shuffle.

The sum of n over all testcases doesn’t exceed 2⋅105. The sum of m over all testcases doesn’t exceed 2⋅105.

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

Example
inputCopy
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
outputCopy
2
3
3

#include <iostream>
#include <algorithm>
using namespace std;
const int N=200010;
int a[N];
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		int n,m;
		cin>>n;
		for(int i=0;i<n;i++) cin>>a[i];
		
		cin>>m;
		int sum=0;
		for(int i=0;i<m;i++)
		{
			int x;
			cin>>x;
			sum+=x;
			sum%=n;
		}
		cout<<a[sum]<<endl;
	}
	return 0;
 } 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值