CF1732D1.Balance (Easy version)

普及/提高-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

This is the easy version of the problem. The only difference is that in this version there are no "remove" queries.

Initially you have a set containing one element — 00. You need to handle qq queries of the following types:

    • xx — add the integer xx to the set. It is guaranteed that this integer is not contained in the set;
  • ? kk — find the k-mexk\text{-mex} of the set.

In our problem, we define the k-mexk\text{-mex} of a set of integers as the smallest non-negative integer xx that is divisible by kk and which is not contained in the set.

这是该问题的简单版本。唯一的区别是,在此版本中没有“删除”查询。

初始时,你有一个只包含一个元素 00 的集合。你需要处理 qq 个如下类型的查询:

    • xx — 将整数 xx 加入集合。保证该整数当前不在集合中;
  • ? kk — 求该集合的 k-mexk\text{-mex}。

在本题中,我们定义一个整数集合的 k-mexk\text{-mex} 为:不小于 00、能被 kk 整除、且不在该集合中的最小整数 xx。

输入格式

The first line contains an integer qq (1≤q≤2⋅1051 \leq q \leq 2 \cdot 10^5) — the number of queries.

The following qq lines describe the queries.

An addition query of integer xx is given in the format + xx (1≤x≤10181 \leq x \leq 10^{18}). It is guaranteed that xx was not contained in the set.

A search query of k-mexk\text{-mex} is given in the format ? kk (1≤k≤10181 \leq k \leq 10^{18}).

It is guaranteed that there will be at least one query of type ?.

第一行包含一个整数 qq(1≤q≤2⋅1051 \leq q \leq 2 \cdot 10^5),表示查询次数。

接下来的 qq 行描述这些查询。

添加查询:格式为 + $x$(1≤x≤10181 \leq x \leq 10^{18}),表示将整数 xx 加入集合。保证 xx 当前不在集合中。

搜索查询:格式为 ? $k$(1≤k≤10181 \leq k \leq 10^{18}),表示查询当前集合的 k-mexk\text{-mex}。

保证至少存在一次类型为 ? 的查询。

输出格式

For each query of type ? output a single integer — the k-mexk\text{-mex} of the set.

对于每个类型为 ? 的查询,输出一个整数——该集合的 k-mexk\text{-mex}。

输入输出样例

  • 输入#1

    15
    + 1
    + 2
    ? 1
    + 4
    ? 2
    + 6
    ? 3
    + 7
    + 8
    ? 1
    ? 2
    + 5
    ? 1
    + 1000000000000000000
    ? 1000000000000000000

    输出#1

    3
    6
    3
    3
    10
    3
    2000000000000000000
  • 输入#2

    6
    + 100
    ? 100
    + 200
    ? 100
    + 50
    ? 50

    输出#2

    200
    300
    150

说明/提示

In the first example:

After the first and second queries, the set will contain elements 0,1,2{0, 1, 2}. The smallest non-negative number that is divisible by 11 and is not contained in the set is 33.

After the fourth query, the set will contain the elements 0,1,2,4{0, 1, 2, 4}. The smallest non-negative number that is divisible by 22 and is not contained in the set is 66.

In the second example:

  • Initially, the set contains only the element 0{0}.
  • After adding an integer 100100 the set contains elements 0,100{0, 100}.
  • 100-mex100\text{-mex} of the set is 200200.
  • After adding an integer 200200 the set contains elements 0,100,200{0, 100, 200}.
  • 100-mex100\text{-mex} of the set is 300300.
  • After adding an integer 5050 the set contains elements 0,50,100,200{0, 50, 100, 200}.
  • 50-mex50\text{-mex} of the set is 150150.

在第一个例子中:

执行第一次和第二次查询后,集合将包含元素 {0,1,2}\{0, 1, 2\}。集合中不包含的、能被 11 整除的最小非负整数是 33。

执行第四次查询后,集合将包含元素 {0,1,2,4}\{0, 1, 2, 4\}。集合中不包含的、能被 22 整除的最小非负整数是 66。

在第二个例子中:

  • 初始时,集合仅包含元素 {0}\{0\}。
  • 添加整数 100100 后,集合包含元素 {0,100}\{0, 100\}。
  • 该集合的 100-mex100\text{-mex} 为 200200。
  • 添加整数 200200 后,集合包含元素 {0,100,200}\{0, 100, 200\}。
  • 该集合的 100-mex100\text{-mex} 为 300300。
  • 添加整数 5050 后,集合包含元素 {0,50,100,200}\{0, 50, 100, 200\}。
  • 该集合的 50-mex50\text{-mex} 为 150150。

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

首页