AT_abc483_b.Flip Card Stack

入门

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

There are NN cards numbered 11 to NN, each with a distinguishable front and back. Initially, they are stacked in the order 1,2,…,N1,2,\ldots,N from the top, all face up.

Takahashi performs QQ operations on this stack. The ii-th operation (1≤i≤Q)(1\leq i\leq Q) is as follows.

Flip the top KiK_i cards over together as a single block and put them back in place.
This reverses the top-to-bottom order of the top KiK_i 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,…,Ni=1,2,\ldots,N, let XiX_i be the number written on the ii-th card from the top; print XiX_i if that card is face up, and −Xi-X_i if it is face down.

有 NN 张编号为 11 至 NN 的卡片,每张卡片具有可区分的正面与背面。初始时,这些卡片按从上到下 1,2,…,N1,2,\ldots,N 的顺序叠放,且全部正面朝上。

高桥对该叠卡片执行 QQ 次操作。第 ii 次操作(1≤i≤Q1\leq i\leq Q)如下:

将最上方的 KiK_i 张卡片作为一个整体一起翻转,并放回原位。
此操作会将这 KiK_i 张卡片的上下顺序反转,同时每张卡片自身也翻面。

求所有操作完成后卡片的排列顺序及朝向。
具体地,对每个 i=1,2,…,Ni=1,2,\ldots,N,设从上往下数第 ii 张卡片上的数字为 XiX_i;若该卡片正面朝上,则输出 XiX_i;若背面朝上,则输出 −Xi-X_i。

输入格式

The input is given from Standard Input in the following format:

NN QQ
K1K_1 K2K_2 ⋯\cdots KQK_Q

输入从标准输入中按以下格式给出:

NN QQ
K1K_1 K2K_2 ⋯\cdots KQK_Q

输出格式

Print NN lines. For the ii-th line (1≤i≤N)(1\leq i\leq N), let XiX_i be the number written on the ii-th card from the top after the QQ operations; print XiX_i if that card is face up, and −Xi-X_i if it is face down.

输出 NN 行。对于第 ii 行(1≤i≤N1\leq i\leq N),设 XiX_i 为经过 QQ 次操作后从顶部数第 ii 张卡片上所写的数字;若该卡片正面朝上,则输出 XiX_i;若该卡片背面朝上,则输出 −Xi-X_i。

输入输出样例

  • 输入#1

    5 2
    3 5

    输出#1

    -5
    -4
    1
    2
    3
  • 输入#2

    1 1
    1

    输出#2

    -1

说明/提示

Sample 1 Explanation:
Below, we write "ii up" for the card numbered ii placed face up, and "ii down" for the card numbered ii placed face down.

Initially, the states of the stacked cards, from the top, are (11 up, 22 up, 33 up, 44 up, 55 up).
The 11-st operation flips the top 33 cards together, so the states become (33 down, 22 down, 11 down, 44 up, 55 up) from the top.
Next, the 22-nd operation flips all of the top 55 cards together, so the states become (55 down, 44 down, 11 up, 22 up, 33 up) from the top.

Thus, print −5,−4,1,2,3-5,-4,1,2,3 in this order, one per line.

Sample 2 Explanation:
After the single operation, the card numbered 11 is face down. Thus, print −1-1.

Constraints

  • 1≤N,Q≤1001 \leq N,Q \leq 100
  • 1≤Ki≤N1 \leq K_i \leq N
  • All input values are integers.

样例 1 解释:
下方中,我们用“ii 上”表示编号为 ii 的牌正面朝上,“ii 下”表示编号为 ii 的牌正面朝下。

初始时,从上到下叠放的牌的状态依次为(11 上,22 上,33 上,44 上,55 上)。
第 11 次操作将最上方的 33 张牌一起翻转,因此从上到下的状态变为(33 下,22 下,11 下,44 上,55 上)。
接着,第 22 次操作将最上方的 55 张牌一起翻转,因此从上到下的状态变为(55 下,44 下,11 上,22 上,33 上)。

因此,按此顺序每行输出 −5,−4,1,2,3-5,-4,1,2,3。

样例 2 解释:
经过唯一一次操作后,编号为 11 的牌正面朝下。因此输出 −1-1。

限制条件

  • 1≤N,Q≤1001 \leq N,Q \leq 100
  • 1≤Ki≤N1 \leq K_i \leq N
  • 所有输入值均为整数。

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

首页