思路是开两个map,一个用于判断数是否出现在set中,另一个存每个数的k-mex。
假设当前我们要找的k对应的答案是x,那么我们利用map找答案的时候,必然会有 0 , k , 2 k , … x − k , 0,k,2k,\dots x-k, 0,k,2k,…x−k,一共 x k \dfrac{x}{k} kx 个数已经在set里了,因此如果k很小,那么插入操作次数就会很多,最后遍历的复杂度不会很高 ,因为 c n t a d d + c n t q u e r y = q cnt_{add}+cnt_{query} = q cntadd+cntquery=q
但是存在 k 1 , k 2 , … k_1,k_2,\dots k1,k2,… 是同一个数的因子qwq,但是这种情况貌似复杂度不会很高,
#include
using namespace std;
typedef long long ll;
ll i,j,k,n,m,t;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
map<ll,ll> f,mp;
mp[0]=1;
cin>>t;
while(t--){
string s;
cin>>s>>k;
if(s=="+")mp[k]=1;
else{
while(mp[f[k]])f[k]+=k;
cout<<f[k]<<'\n';
}
}
}