1681 B Card Trick(无限循环数组)

这篇文章介绍了一个关于观察者如何通过观察洗牌过程预测魔术后顶部牌的数学谜题。通过理解每次洗牌的影响并应用周期性,解决者能够揭示出即使在多次复杂操作后,卡片的真实位置。关键在于理解操作的累积效应和取模运算在问题中的运用。

B. Card Trick

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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,…,ana1,a2,…,an, and all values are different.

Then he asks you to shuffle the deck mm times. With the jj-th shuffle, you should take bjbj topmost cards and move them under the remaining (n−bj)(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 tt (1≤t≤1041≤t≤104) — the number of testcases.

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

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

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

The fourth line contains mm integers b1,b2,…,bmb1,b2,…,bm (1≤bj≤n−11≤bj≤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⋅105. The sum of mm over all testcases doesn't exceed 2⋅1052⋅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 mm times.

Example

input

Copy

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

output

Copy

2
3
3

Note

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.

无限循环数组,这个是一维的所以,把操作数对数组长度n取模就能随时提取操作后数组的第一个数

#include<iostream>
#include<algorithm>
using namespace std;
const int manx = 2e5 + 10;
int a[manx];
int b[manx];
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;
		long long sum = 0;
		for (int i = 0; i < m; i++)
		{
			cin >> b[i];
			sum += b[i];
		}
		sum = sum % n;
		cout << a[sum] << endl;
	}
}

### Wine 使用技巧与方法 Wine 是一个开源项目,旨在让 Linux 和其他类 Unix 系统能够运行 Windows 应用程序。它通过模仿 Windows API 来实现这一目标,而无需实际安装 Windows 操作系统。以下是一些关于使用 Wine 的技巧和方法[^1]。 #### 安装应用程序 要安装 Windows 应用程序,用户可以简单地双击 `.exe` 文件,或者在终端中运行 `wine <application_name>.exe`。如果需要更高级的安装选项,可以使用 Winetricks 工具来安装依赖项和库[^2]。 ```bash winetricks vcrun2019 ``` 上述命令将安装 Visual C++ 2019 Redistributable,这是许多现代 Windows 应用程序所必需的。 #### 调整图形设置 某些应用程序可能需要特定的 DirectX 或 OpenGL 设置才能正常运行。可以通过 `winecfg` 工具调整这些设置: ```bash winecfg ``` 在 `Graphics` 标签页中,可以启用或禁用虚拟桌面,并调整分辨率和其他图形相关选项[^3]。 #### 使用前缀隔离环境 Wine 允许创建多个前缀(prefix),每个前缀相当于一个独立的 Windows 环境。这有助于隔离不同应用程序之间的冲突。创建新前缀的方法如下: ```bash WINEPREFIX=~/.new_prefix wineboot --init ``` 然后,在该前缀下运行应用程序时,需指定相同的 `WINEPREFIX` 环境变量。 #### 日志调试 如果某个应用程序无法正常运行,可以启用调试日志以获取更多信息。通过设置 `WINEDEBUG` 环境变量,可以控制输出的日志级别: ```bash WINEDEBUG=+all wine <application_name>.exe ``` 注意,生成的日志文件可能会非常大,因此建议仅在需要时启用此功能[^4]。 #### 性能优化 为了提高性能,可以禁用不必要的功能,例如字体平滑和视觉主题。同样,可以在 `winecfg` 中调整 CPU 数量和内存分配。 ```python import os # 设置 WINEDEBUG 环境变量 os.environ['WINEDEBUG'] = '+all' ``` #### 注意事项 确保系统已安装所有必要的依赖项,包括 32 位和 64 位库。此外,某些应用程序可能需要特定版本的 Wine 才能正常工作。在这种情况下,可以尝试使用 Wine Staging 版本,它通常包含更多实验性功能和支持[^5]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值