CF1184D1.Parallel Universes (Easy)

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The Third Doctor Who once correctly said that travel between parallel universes is "like travelling sideways". However, he incorrectly thought that there were infinite parallel universes, whereas in fact, as we now all know, there will never be more than 250.

Heidi recently got her hands on a multiverse observation tool. She was able to see all nn universes lined up in a row, with non-existent links between them. She also noticed that the Doctor was in the kk-th universe.

The tool also points out that due to restrictions originating from the space-time discontinuum, the number of universes will never exceed mm.

Obviously, the multiverse is unstable because of free will. Each time a decision is made, one of two events will randomly happen: a new parallel universe is created, or a non-existent link is broken.

More specifically,

  • When a universe is created, it will manifest itself between any two adjacent universes or at one of the ends.
  • When a link is broken, it could be cut between any two adjacent universes. After separating the multiverse into two segments, the segment NOT containing the Doctor will cease to exist.

Heidi wants to perform a simulation of tt decisions. Each time a decision is made, Heidi wants to know the length of the multiverse (i.e. the number of universes), and the position of the Doctor.

第三任博士曾正确指出,平行宇宙之间的旅行是“横向移动”。然而,他错误地认为存在无限多个平行宇宙;而事实上,正如我们现在所知,平行宇宙的数量永远不会超过 250250 个。

海蒂最近获得了一台多元宇宙观测工具。她得以观察到排成一行的全部 nn 个宇宙,这些宇宙之间尚无任何连接。她还注意到,博士正位于第 kk 个宇宙中。

该工具同时指出:由于源自时空不连续体的限制,宇宙的总数将永远不会超过 mm。

显然,由于自由意志的存在,多元宇宙本身并不稳定。每次做出一个决定时,以下两种事件之一将随机发生:创建一个新的平行宇宙,或切断一条尚未存在的连接。

更具体地说:

  • 当创建一个新宇宙时,它将出现在任意两个相邻宇宙之间,或出现在整行宇宙的任一端点处;
  • 当切断一条连接时,该连接可被切断于任意两个相邻宇宙之间。切断后,多元宇宙将分裂为两个片段;不包含博士的那个片段将立即消失。

海蒂希望对 tt 次决策进行模拟。每次做出决策后,海蒂都想知道当前多元宇宙的长度(即宇宙的总数)以及博士所在的位置。

输入格式

The first line contains four integers nn, kk, mm and tt (2≤k≤n≤m≤2502 \le k \le n \le m \le 250, 1≤t≤10001 \le t \le 1000).

Each of the following tt lines is in one of the following formats:

  • "11 ii" — meaning that a universe is inserted at the position ii (1≤i≤l+11 \le i \le l + 1), where ll denotes the current length of the multiverse.
  • "00 ii" — meaning that the ii-th link is broken (1≤i≤l−11 \le i \le l - 1), where ll denotes the current length of the multiverse.

第一行包含四个整数 nn、kk、mm 和 tt(2≤k≤n≤m≤2502 \le k \le n \le m \le 250,1≤t≤10001 \le t \le 1000)。

接下来的 tt 行中,每行均为以下两种格式之一:

  • “11 ii” — 表示在位置 ii 插入一个宇宙(1≤i≤l+11 \le i \le l + 1),其中 ll 表示当前多重宇宙的长度。
  • “00 ii” — 表示第 ii 条连接被断开(1≤i≤l−11 \le i \le l - 1),其中 ll 表示当前多重宇宙的长度。

输出格式

Output tt lines. Each line should contain ll, the current length of the multiverse and kk, the current position of the Doctor.

It is guaranteed that the sequence of the steps will be valid, i.e. the multiverse will have length at most mm and when the link breaking is performed, there will be at least one universe in the multiverse.

输出 tt 行。每行应包含两个整数:ll(当前多重宇宙的长度)和 kk(博士当前所在的位置)。

保证操作序列是合法的,即多重宇宙的长度至多为 mm,且在执行“断链”操作时,多重宇宙中至少存在一个宇宙。

输入输出样例

  • 输入#1

    5 2 10 4
    0 1
    1 1
    0 4
    1 2

    输出#1

    4 1
    5 2
    4 2
    5 3

说明/提示

The multiverse initially consisted of 5 universes, with the Doctor being in the second.

First, link 1 was broken, leaving the multiverse with 4 universes, and the Doctor in the first.

Then, a universe was added to the leftmost end of the multiverse, increasing the multiverse length to 5, and the Doctor was then in the second universe.

Then, the rightmost link was broken.

Finally, a universe was added between the first and the second universe.

多元宇宙最初由 5 个宇宙组成,博士位于第二个宇宙中。

首先,第 1 条连接被断开,多元宇宙剩下 4 个宇宙,博士位于第一个宇宙中。

接着,在多元宇宙最左端添加了一个宇宙,使其长度增至 5,此时博士位于第二个宇宙中。

然后,最右端的连接被断开。

最后,在第一个宇宙与第二个宇宙之间添加了一个宇宙。

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

首页