set 是一种能在 的时间复杂度内完成插入、删除操作的容器。
s.insert(x):向集合 中插入元素 ;
s.size():set 是不可重集合,表示集合中不同元素个数。
#include<bits/stdc++.h>
using namespace std;
set<int>s;
int main(){
int x,n,op;
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
while(n--){
cin>>op;
if(op==1)cin>>x,s.insert(x);
else cout<<s.size()<<'\n';
}
}
暂无评论