logo AlgoBeat OnlineJudge
登录 注册

题解

作者: _ZXY_  ·  发布于 2026-07-02 16:48:47  ·  最后修改于 2026-07-02 17:39:09
已通过
审核员:AlgoBeat 官方账号 · 2026-07-02 17:39:09

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';
    }
}

暂无评论

登录 后即可评论。