A15455 | Balance (Easy version)
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 — $0$ . You need to handle $q$ queries of the following types:
- + $x$ — add the integer $x$ to the set. It is guaranteed that this integer is not contained in the set;
- ? $k$ — find the $k\text{-mex}$ of the set.
In our problem, we define the $k\text{-mex}$ of a set of integers as the smallest non-negative integer $x$ that is divisible by $k$ and which is not contained in the set.
Initially you have a set containing one element — $0$ . You need to handle $q$ queries of the following types:
- + $x$ — add the integer $x$ to the set. It is guaranteed that this integer is not contained in the set;
- ? $k$ — find the $k\text{-mex}$ of the set.
In our problem, we define the $k\text{-mex}$ of a set of integers as the smallest non-negative integer $x$ that is divisible by $k$ and which is not contained in the set.
输入格式
The first line contains an integer $q$ ( $1 \leq q \leq 2 \cdot 10^5$ ) — the number of queries.
The following $q$ lines describe the queries.
An addition query of integer $x$ is given in the format + $x$ ( $1 \leq x \leq 10^{18}$ ). It is guaranteed that $x$ was not contained in the set.
A search query of $k\text{-mex}$ is given in the format ? $k$ ( $1 \leq k \leq 10^{18}$ ).
It is guaranteed that there will be at least one query of type ?.
The following $q$ lines describe the queries.
An addition query of integer $x$ is given in the format + $x$ ( $1 \leq x \leq 10^{18}$ ). It is guaranteed that $x$ was not contained in the set.
A search query of $k\text{-mex}$ is given in the format ? $k$ ( $1 \leq k \leq 10^{18}$ ).
It is guaranteed that there will be at least one query of type ?.
输出格式
For each query of type ? output a single integer — the $k\text{-mex}$ of the set.
输入输出样例
输入 #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\}$ . The smallest non-negative number that is divisible by $1$ and is not contained in the set is $3$ .
After the fourth query, the set will contain the elements $\{0, 1, 2, 4\}$ . The smallest non-negative number that is divisible by $2$ and is not contained in the set is $6$ .
In the second example:
- Initially, the set contains only the element $\{0\}$ .
- After adding an integer $100$ the set contains elements $\{0, 100\}$ .
- $100\text{-mex}$ of the set is $200$ .
- After adding an integer $200$ the set contains elements $\{0, 100, 200\}$ .
- $100\text{-mex}$ of the set is $300$ .
- After adding an integer $50$ the set contains elements $\{0, 50, 100, 200\}$ .
- $50\text{-mex}$ of the set is $150$ .
After the first and second queries, the set will contain elements $\{0, 1, 2\}$ . The smallest non-negative number that is divisible by $1$ and is not contained in the set is $3$ .
After the fourth query, the set will contain the elements $\{0, 1, 2, 4\}$ . The smallest non-negative number that is divisible by $2$ and is not contained in the set is $6$ .
In the second example:
- Initially, the set contains only the element $\{0\}$ .
- After adding an integer $100$ the set contains elements $\{0, 100\}$ .
- $100\text{-mex}$ of the set is $200$ .
- After adding an integer $200$ the set contains elements $\{0, 100, 200\}$ .
- $100\text{-mex}$ of the set is $300$ .
- After adding an integer $50$ the set contains elements $\{0, 50, 100, 200\}$ .
- $50\text{-mex}$ of the set is $150$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted