結果

問題 No.2195 AND Set
ユーザー umezo
提出日時 2023-01-20 22:37:16
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 206 ms / 2,000 ms
コード長 841 bytes
コンパイル時間 1,743 ms
コンパイル使用メモリ 200,688 KB
最終ジャッジ日時 2025-02-10 05:04:02
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int q;
  cin>>q;
  set<int> s;
  vector<int> A(30);
  rep(_,q){
    int c;
    cin>>c;
    if(c==1){
      int x;
      cin>>x;
      if(s.count(x)) continue;
      s.insert(x);
      rep(i,30){
        if(x&(1<<i)) A[i]++;
      }
    }
    else if(c==2){
      int x;
      cin>>x;
      if(!s.count(x)) continue;
      s.erase(x);
      rep(i,30){
        if(x&(1<<i)) A[i]--;
      }
    }
    else{
      int ans=0;
      int si=s.size();
      if(si==0){
        cout<<-1<<'\n';
        continue;
      }
      rep(i,30){
        if(A[i]==si) ans+=(1<<i);
      }
      cout<<ans<<'\n';
    }
  }
  
  return 0;
}
0