D1. Balance (Easy version)
创始人
2024-05-31 10:29:00
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 — 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-mex of the set.

In our problem, we define the k-mexk-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.

Input

The first line contains an integer qq (1≤q≤2⋅1051≤q≤2⋅105) — 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≤x≤1018). It is guaranteed that xx was not contained in the set.

A search query of k-mexk-mex is given in the format ? kk (1≤k≤10181≤k≤1018).

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

Output

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

Examples

input

Copy

 

15

+ 1

+ 2

? 1

+ 4

? 2

+ 6

? 3

+ 7

+ 8

? 1

? 2

+ 5

? 1

+ 1000000000000000000

? 1000000000000000000

output

Copy

3
6
3
3
10
3
2000000000000000000

input

Copy

 

6

+ 100

? 100

+ 200

? 100

+ 50

? 50

output

Copy

200
300
150

Note

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-mex of the set is 200200.
  • After adding an integer 200200 the set contains elements {0,100,200}{0,100,200}.
  • 100-mex100-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-mex of the set is 150150.

解析:

 要求这个列表当中能被k整除的最小非负元素,且这个元素不被列表包含 。那么很显然,只要从k开始考虑是否满足,如果不满足那就考虑k的倍数是否满足就可以了,但是如果每次询问k的时候都从自身开始加的话绝对会TLE(别问我是怎么知道的),那么这个时候就要节约时间,那么每次询问k并且找到答案之后,就将此时的答案记录的k这个位置,下次再问到k的时候就从这个记录的答案开始找,那么就会节约很多 的时间

ac代码:

 

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include 
#include
#include
#include
#define dbug cout<<"hear!"<=b;i--)
#define pper(a,b) for(ll j=a;j>=b;j--)
#define no cout<<"NO"<,greater >q;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair PII;
const int N = 2e5 + 100;
const int  INF = 0x3f3f3f3f;
ll gcdd(ll a, ll b)
{if (b) while ((a %= b) && (b %= a));return a + b;
}
ll h[N], ne[N], w[N], to[N], idx;
void add(int a, int b, int c)
{to[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx++;
}
const int mod = 998244353;
ll t, n, m, a, b, c,d, x,y, k, cnt, ans, ant, sum,q, p;
ll arr[N], brr[N], crr[N];int main()
{cin >> n; mapmp, mmp;while (n--){char o;cin >> o >> x;if (o == '+'){mp[x]++;// cout << mp[x] << endl;}else{ant = x;if (!mmp[x])mmp[x] = x;x = mmp[x];while (mp[x]){x += ant;}mmp[ant] = x;cout << x << endl;}}
}

相关内容

热门资讯

喜欢穿一身黑的男生性格(喜欢穿... 今天百科达人给各位分享喜欢穿一身黑的男生性格的知识,其中也会对喜欢穿一身黑衣服的男人人好相处吗进行解...
发春是什么意思(思春和发春是什... 本篇文章极速百科给大家谈谈发春是什么意思,以及思春和发春是什么意思对应的知识点,希望对各位有所帮助,...
网络用语zl是什么意思(zl是... 今天给各位分享网络用语zl是什么意思的知识,其中也会对zl是啥意思是什么网络用语进行解释,如果能碰巧...
为什么酷狗音乐自己唱的歌不能下... 本篇文章极速百科小编给大家谈谈为什么酷狗音乐自己唱的歌不能下载到本地?,以及为什么酷狗下载的歌曲不是...
华为下载未安装的文件去哪找(华... 今天百科达人给各位分享华为下载未安装的文件去哪找的知识,其中也会对华为下载未安装的文件去哪找到进行解...
怎么往应用助手里添加应用(应用... 今天百科达人给各位分享怎么往应用助手里添加应用的知识,其中也会对应用助手怎么添加微信进行解释,如果能...
家里可以做假山养金鱼吗(假山能... 今天百科达人给各位分享家里可以做假山养金鱼吗的知识,其中也会对假山能放鱼缸里吗进行解释,如果能碰巧解...
一帆风顺二龙腾飞三阳开泰祝福语... 本篇文章极速百科给大家谈谈一帆风顺二龙腾飞三阳开泰祝福语,以及一帆风顺二龙腾飞三阳开泰祝福语结婚对应...
四分五裂是什么生肖什么动物(四... 本篇文章极速百科小编给大家谈谈四分五裂是什么生肖什么动物,以及四分五裂打一生肖是什么对应的知识点,希...
美团联名卡审核成功待激活(美团... 今天百科达人给各位分享美团联名卡审核成功待激活的知识,其中也会对美团联名卡审核未通过进行解释,如果能...