CF2115F1.Gellyfish and Lycoris Radiata (Easy Version)

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

This is the easy version of the problem. The difference between the versions is that in this version, the time limit and the constraints on nn and qq are lower. You can hack only if you solved all versions of this problem.

Gellyfish has an array consisting of nn sets. Initially, all the sets are empty.

Now Gellyfish will do qq operations. Each operation contains one modification operation and one query operation, for the ii-th (1≤i≤q1 \leq i \leq q) operation:

First, there will be a modification operation, which is one of the following:

  1. Insert operation: You are given an integer rr. For the 11-th to rr-th sets, insert element ii. Note that the element inserted here is ii, the index of the operation, not the index of the set.
  2. Reverse operation: You are given an integer rr. Reverse the 11-th to rr-th sets.
  3. Delete operation: You are given an integer xx. Delete element xx from all sets that contain xx.

Followed by a query operation:

  • Query operation: You are given an integer pp. Output the smallest element in the pp-th set (If the pp-th set is empty, the answer is considered to be 00).

Now, Flower needs to provide the answer for each query operation. Please help her!

Additional constraint on the problem: Gellyfish will only give the next operation after Flower has answered the previous query operation. That is, you need to solve this problem online. Please refer to the input format for more details.

这是该问题的简单版本。两个版本的区别在于:在此版本中,时间限制以及 nn 和 qq 的约束更小。仅当你已解决该问题的所有版本时,才允许你进行 Hack。

Gellyfish 拥有一个由 nn 个集合组成的数组。初始时,所有集合均为空。

接下来 Gellyfish 将执行 qq 次操作。每次操作包含一次修改操作和一次查询操作;对于第 ii 次操作(1≤i≤q1 \leq i \leq q):

首先,执行一次修改操作,其类型为以下之一:

  1. 插入操作:给定一个整数 rr。对第 11 个至第 rr 个集合,插入元素 ii。(注意:此处插入的元素是操作的索引 ii,而非集合的索引。)
  2. 翻转操作:给定一个整数 rr。将第 11 个至第 rr 个集合进行翻转。
  3. 删除操作:给定一个整数 xx。从所有包含元素 xx 的集合中删除 xx。

随后,执行一次查询操作:

  • 查询操作:给定一个整数 pp。输出第 pp 个集合中的最小元素(若第 pp 个集合为空,则答案视为 00)。

现在,Flower 需要为每次查询操作提供答案。请帮助她!

本题附加约束:Gellyfish 仅在 Flower 回答完上一次查询操作后,才会给出下一次操作。即,你需要在线求解本题。更多细节请参阅输入格式说明。

输入格式

The first line contains two integers nn and qq (1≤n,q≤1051 \leq n, q \leq 10^5) — the number of the sets and the number of operations.

As you need to respond to the operations online, the operations will be encoded.

The ii-th line of the following qq lines contains three integers aa, bb, and cc (1≤a≤31 \leq a \leq 3, 1≤c≤n1 \leq c \leq n) — describing the ii-th operation in an encoded form.

Here, aa represents the type of modification operation. Among them, a=1a=1 represents Insert operation, a=2a=2 represents Reverse operation, a=3a=3 represents Delete operation.

  • If a=1a = 1, then the modification operation is the Insert operation. It will be guaranteed that 1≤b≤n1 \leq b \leq n. rr will be calculated as r=(b+ansi−1−1) mod n+1r=(b+\text{ans}_{i-1}-1) \bmod n + 1.
  • If a=2a=2, then the modification operation is the Reverse operation. It will be guaranteed that 1≤b≤n1 \leq b \leq n. rr will be calculated as r=(b+ansi−1−1) mod n+1r=(b+\text{ans}_{i-1}-1) \bmod n + 1.
  • If a=3a=3, then the modification operation is the Delete operation. It will be guaranteed that 1≤b≤q1 \leq b \leq q. xx will be calculated as x=(b+ansi−1−1) mod q+1x=(b+\text{ans}_{i-1}-1) \bmod q + 1.

For the query operation, pp will be calculated as p=(c+ansi−1−1) mod n+1p = (c+\text{ans}_{i-1}-1) \bmod n + 1.

Here $ \text{ans}{i} (1 \leq i \leq q)$ represents the answer to the query operation in the ii-th operation. Additionally, we define $ \text{ans}{0} = 0$.

第一行包含两个整数 nn 和 qq(1≤n,q≤1051 \leq n, q \leq 10^5)——分别表示集合的数量和操作的数量。

由于你需要在线响应这些操作,因此所有操作均经过编码。

接下来的 qq 行中,第 ii 行包含三个整数 aa、bb 和 cc(1≤a≤31 \leq a \leq 3,1≤c≤n1 \leq c \leq n)——以编码形式描述第 ii 个操作。

其中,aa 表示修改操作的类型:a=1a=1 表示插入操作(Insert),a=2a=2 表示翻转操作(Reverse),a=3a=3 表示删除操作(Delete)。

  • 若 a=1a = 1,则该修改操作为插入操作。保证满足 1≤b≤n1 \leq b \leq n。rr 的计算方式为 r=(b+ansi−1−1) mod n+1r=(b+\text{ans}_{i-1}-1) \bmod n + 1。
  • 若 a=2a=2,则该修改操作为翻转操作。保证满足 1≤b≤n1 \leq b \leq n。rr 的计算方式为 r=(b+ansi−1−1) mod n+1r=(b+\text{ans}_{i-1}-1) \bmod n + 1。
  • 若 a=3a=3,则该修改操作为删除操作。保证满足 1≤b≤q1 \leq b \leq q。xx 的计算方式为 x=(b+ansi−1−1) mod q+1x=(b+\text{ans}_{i-1}-1) \bmod q + 1。

对于查询操作,pp 的计算方式为 p=(c+ansi−1−1) mod n+1p = (c+\text{ans}_{i-1}-1) \bmod n + 1。

此处,ansi\text{ans}_{i}(1≤i≤q1 \leq i \leq q)表示第 ii 个操作中查询操作的答案。此外,我们定义 ans0=0\text{ans}_{0} = 0。

输出格式

For each query operation, output the answer to the query.

对于每个查询操作,输出该查询的答案。

输入输出样例

  • 输入#1

    5 10
    1 2 2
    2 3 1
    1 5 3
    2 2 5
    1 5 2
    2 4 4
    3 2 2
    3 1 2
    3 10 5
    3 2 4

    输出#1

    1
    0
    1
    1
    3
    1
    0
    5
    0
    0

说明/提示

All the sets are empty in the beginning, so the array is [,,,,][{}, {}, {}, {}, {}].

With the decoding method given before, we can see what happens in each operation:

  1. For the first operation: a=1,r=2,p=2a = 1, r = 2, p = 2. The modification operation is an Insert operation; element 11 is inserted into the first two sets; so the array becomes [1,1,,,][{1}, {1}, {}, {}, {}], and the smallest element in the second set is 11.
  2. For the second operation: a=2,r=4,p=2a = 2, r = 4, p = 2. The modification operation is a Reverse operation; the first four sets are reversed; so the array becomes [,,1,1,][{}, {}, {1}, {1}, {}], and the second set is empty, which means the answer is 00.
  3. For the third operation: a=1,r=5,p=3a = 1, r = 5, p = 3. The modification operation is an Insert operation; element 33 is inserted into all the sets; so the array becomes [3,3,1,3,1,3,3][{3}, {3}, {1, 3}, {1, 3}, {3}], and the smallest element in the third set is 11.
  4. For the fourth operation: a=2,r=3,p=1a = 2, r = 3, p = 1. The modification operation is a Reverse operation; the first three sets are reversed; so the array becomes [1,3,3,3,1,3,3][{1, 3}, {3}, {3}, {1, 3}, {3}], and the smallest element in the first set is 11.
  5. For the fifth operation: a=1,r=1,p=3a = 1, r = 1, p = 3. The modification operation is an Insert operation; element 55 is inserted into the first set; so the array becomes [1,3,5,3,3,1,3,3][{1, 3, 5}, {3}, {3}, {1, 3}, {3}], and the smallest element in the third set is 33.
  6. For the sixth operation: a=2,r=2,p=2a = 2, r = 2, p = 2. The modification operation is a Reverse operation; the first two sets are reversed; so the array becomes [3,1,3,5,3,1,3,3][{3}, {1, 3, 5}, {3}, {1, 3}, {3}], and the smallest element in the second set is 11.
  7. For the seventh operation: a=3,x=3,p=3a = 3, x = 3, p = 3. The modification operation is a Delete operation; element 33 is deleted from all the sets; so the array becomes [,1,5,,1,][{}, {1, 5}, {}, {1}, {}], and the third set is empty, which means the answer is 00.
  8. For the eighth operation: a=3,x=1,p=2a = 3, x = 1, p = 2. The modification operation is a Delete operation; element 11 is deleted from all the sets; so the array becomes [,5,,,][{}, {5}, {}, {}, {}], and the smallest element in the second set is 55.
  9. For the ninth operation: a=3,x=5,p=5a = 3, x = 5, p = 5. The modification operation is a Delete operation; element 55 is deleted from all the sets; so the array becomes [,,,,][{}, {}, {}, {}, {}], and the fifth set is empty, which means the answer is 00.
  10. For the tenth operation: a=3,x=2,p=4a = 3, x = 2, p = 4. The modification operation is a Delete operation; element 22 is deleted from all the sets; so the array becomes [,,,,][{}, {}, {}, {}, {}], and the fourth set is empty, which means the answer is 00.

Please note that although we have not inserted element 22 into the sets, we still delete element 22 from all the sets in the tenth operation, which means that the Delete operation doesn't necessarily require the existence of a set to contain the deleted element. It also shows that it is possible to have two Delete operations that delete the same element.

所有集合初始时均为空,因此数组为 [,,,,][{}, {}, {}, {}, {}]。

根据之前给出的解码方法,我们可以观察每次操作中发生的变化:

  1. 第一次操作:a=1,r=2,p=2a = 1, r = 2, p = 2。该修改操作为插入(Insert)操作;将元素 11 插入前两个集合;因此数组变为 [1,1,,,][{1}, {1}, {}, {}, {}],第二个集合中的最小元素为 11。
  2. 第二次操作:a=2,r=4,p=2a = 2, r = 4, p = 2。该修改操作为翻转(Reverse)操作;将前四个集合翻转;因此数组变为 [,,1,1,][{}, {}, {1}, {1}, {}],第二个集合为空,故答案为 00。
  3. 第三次操作:a=1,r=5,p=3a = 1, r = 5, p = 3。该修改操作为插入(Insert)操作;将元素 33 插入所有集合;因此数组变为 [3,3,1,3,1,3,3][{3}, {3}, {1, 3}, {1, 3}, {3}],第三个集合中的最小元素为 11。
  4. 第四次操作:a=2,r=3,p=1a = 2, r = 3, p = 1。该修改操作为翻转(Reverse)操作;将前三个集合翻转;因此数组变为 [1,3,3,3,1,3,3][{1, 3}, {3}, {3}, {1, 3}, {3}],第一个集合中的最小元素为 11。
  5. 第五次操作:a=1,r=1,p=3a = 1, r = 1, p = 3。该修改操作为插入(Insert)操作;将元素 55 插入第一个集合;因此数组变为 [1,3,5,3,3,1,3,3][{1, 3, 5}, {3}, {3}, {1, 3}, {3}],第三个集合中的最小元素为 33。
  6. 第六次操作:a=2,r=2,p=2a = 2, r = 2, p = 2。该修改操作为翻转(Reverse)操作;将前两个集合翻转;因此数组变为 [3,1,3,5,3,1,3,3][{3}, {1, 3, 5}, {3}, {1, 3}, {3}],第二个集合中的最小元素为 11。
  7. 第七次操作:a=3,x=3,p=3a = 3, x = 3, p = 3。该修改操作为删除(Delete)操作;从所有集合中删除元素 33;因此数组变为 [,1,5,,1,][{}, {1, 5}, {}, {1}, {}],第三个集合为空,故答案为 00。
  8. 第八次操作:a=3,x=1,p=2a = 3, x = 1, p = 2。该修改操作为删除(Delete)操作;从所有集合中删除元素 11;因此数组变为 [,5,,,][{}, {5}, {}, {}, {}],第二个集合中的最小元素为 55。
  9. 第九次操作:a=3,x=5,p=5a = 3, x = 5, p = 5。该修改操作为删除(Delete)操作;从所有集合中删除元素 55;因此数组变为 [,,,,][{}, {}, {}, {}, {}],第五个集合为空,故答案为 00。
  10. 第十次操作:a=3,x=2,p=4a = 3, x = 2, p = 4。该修改操作为删除(Delete)操作;从所有集合中删除元素 22;因此数组变为 [,,,,][{}, {}, {}, {}, {}],第四个集合为空,故答案为 00。

请注意:尽管我们从未向集合中插入过元素 22,但在第十次操作中仍需从所有集合中删除元素 22,这表明删除(Delete)操作并不要求被删元素必须存在于某个集合中。这也说明,有可能出现两次删除同一元素的操作。

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

首页