Codeforces Round 830 (Div. 2) D1. Balance (Easy version)

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-mex of the set.

In our problem, we define the k-mex-mex of a set of integers as the smallest non-negative integer xthat is divisible by k and which is not contained in the set.

MarkDown视图Copy翻译

Input

The first line contains an integer q(1≤q≤2⋅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≤x≤10^18). It is guaranteed that x was not contained in the set.

A search query of k-mex is given in the format ? k (1≤k≤10^18).

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

MarkDown视图Copy翻译

Output

For each query of type ? output a single integer — the k-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}. 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-mex of the set is 200.
  • After adding an integer 200 the set contains elements {0,100,200}.
  • 100-mexof the set is 300.
  • After adding an integer 50 the set contains elements {0,50,100,200}.
  • 50-mex of the set is 150.

拿第二个map mm 来维护k 的倍数,即出现相同k的查询时,直接从k的倍数开始输出;

#include
using namespace std;
//#pragma GCC optimize(2)
#define  endl '\n'
#define lowbit(x) ((x)&-(x))
const int mod=1e9+7;
typedef long long ll;
ll ans=0,n1,m1;
ll t,s1,s2,s3,s4,max1=0,min1=100000000,sum=0,n,m,i,j,k,l,r;
ll u,v,w;
inline int read() {
	bool sym=0;
	int res=0;
	char ch=getchar();
	while(!isdigit(ch))sym |=(ch =='-'),ch=getchar();
	while(isdigit(ch)) res =(res<<3)+(res<<1)+(ch^48),ch=getchar();
	return sym ? -res : res;
}
void print(int x) {
	if(!x)return;
	print(x/10);
	putchar(x%10+'0');
}
int isPrime(int n) {
	float n_sqrt;
	if(n==1) return 0;
	if(n==2 || n==3) return 1;
	if(n%6!=1 && n%6!=5) return 0;
	n_sqrt=floor(sqrt((float)n));
	for(int i=5; i<=n_sqrt; i+=6) {
		if(n%(i)==0 | n%(i+2)==0) return 0;
	}
	return 1;
}
ll a[100086];
string ss;
char as;
setst;
mapmp;
mapmm;
int main() {


	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin>>t;
	while(t--) {
cin>>as;
if(as=='+')
		{
			cin>>s1;
			mp[s1]++;
		}
else
{
	cin>>s1;
	k=s1;
	if(mm[s1]!=0)
	s1=mm[s1];
	
	while(mp[s1]!=0){
		s1+=k;
	}
	mm[k]=s1;
	cout<

你可能感兴趣的:(c语言,算法,STL,map)