AT_abc483_b.Flip Card Stack
入门
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are N cards numbered 1 to N, each with a distinguishable front and back. Initially, they are stacked in the order 1,2,…,N from the top, all face up.
Takahashi performs Q operations on this stack. The i-th operation (1≤i≤Q) is as follows.
Flip the top Ki cards over together as a single block and put them back in place.
This reverses the top-to-bottom order of the top Ki cards and also turns each of those cards over.
Find the order and orientation of the cards after all operations.
Specifically, for each i=1,2,…,N, let Xi be the number written on the i-th card from the top; print Xi if that card is face up, and −Xi if it is face down.
有 N 张编号为 1 至 N 的卡片,每张卡片具有可区分的正面与背面。初始时,这些卡片按从上到下 1,2,…,N 的顺序叠放,且全部正面朝上。
高桥对该叠卡片执行 Q 次操作。第 i 次操作(1≤i≤Q)如下:
将最上方的 Ki 张卡片作为一个整体一起翻转,并放回原位。
此操作会将这 Ki 张卡片的上下顺序反转,同时每张卡片自身也翻面。
求所有操作完成后卡片的排列顺序及朝向。
具体地,对每个 i=1,2,…,N,设从上往下数第 i 张卡片上的数字为 Xi;若该卡片正面朝上,则输出 Xi;若背面朝上,则输出 −Xi。
输入格式
The input is given from Standard Input in the following format:
N Q
K1 K2 ⋯ KQ
输入从标准输入中按以下格式给出:
N Q
K1 K2 ⋯ KQ
输出格式
Print N lines. For the i-th line (1≤i≤N), let Xi be the number written on the i-th card from the top after the Q operations; print Xi if that card is face up, and −Xi if it is face down.
输出 N 行。对于第 i 行(1≤i≤N),设 Xi 为经过 Q 次操作后从顶部数第 i 张卡片上所写的数字;若该卡片正面朝上,则输出 Xi;若该卡片背面朝上,则输出 −Xi。
输入输出样例
输入#1
5 2 3 5
输出#1
-5 -4 1 2 3
输入#2
1 1 1
输出#2
-1
说明/提示
Sample 1 Explanation:
Below, we write "i up" for the card numbered i placed face up, and "i down" for the card numbered i placed face down.
Initially, the states of the stacked cards, from the top, are (1 up, 2 up, 3 up, 4 up, 5 up).
The 1-st operation flips the top 3 cards together, so the states become (3 down, 2 down, 1 down, 4 up, 5 up) from the top.
Next, the 2-nd operation flips all of the top 5 cards together, so the states become (5 down, 4 down, 1 up, 2 up, 3 up) from the top.
Thus, print −5,−4,1,2,3 in this order, one per line.
Sample 2 Explanation:
After the single operation, the card numbered 1 is face down. Thus, print −1.
Constraints
- 1≤N,Q≤100
- 1≤Ki≤N
- All input values are integers.
样例 1 解释:
下方中,我们用“i 上”表示编号为 i 的牌正面朝上,“i 下”表示编号为 i 的牌正面朝下。
初始时,从上到下叠放的牌的状态依次为(1 上,2 上,3 上,4 上,5 上)。
第 1 次操作将最上方的 3 张牌一起翻转,因此从上到下的状态变为(3 下,2 下,1 下,4 上,5 上)。
接着,第 2 次操作将最上方的 5 张牌一起翻转,因此从上到下的状态变为(5 下,4 下,1 上,2 上,3 上)。
因此,按此顺序每行输出 −5,−4,1,2,3。
样例 2 解释:
经过唯一一次操作后,编号为 1 的牌正面朝下。因此输出 −1。
限制条件
- 1≤N,Q≤100
- 1≤Ki≤N
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?