結果

問題 No.2195 AND Set
ユーザー umezoumezo
提出日時 2023-01-20 22:37:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 219 ms / 2,000 ms
コード長 841 bytes
コンパイル時間 1,934 ms
コンパイル使用メモリ 206,184 KB
実行使用メモリ 8,308 KB
最終ジャッジ日時 2023-09-05 14:58:23
合計ジャッジ時間 5,481 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 127 ms
4,380 KB
testcase_03 AC 154 ms
5,024 KB
testcase_04 AC 124 ms
4,376 KB
testcase_05 AC 137 ms
4,956 KB
testcase_06 AC 135 ms
4,888 KB
testcase_07 AC 100 ms
4,384 KB
testcase_08 AC 133 ms
4,888 KB
testcase_09 AC 89 ms
4,380 KB
testcase_10 AC 212 ms
8,060 KB
testcase_11 AC 219 ms
8,308 KB
testcase_12 AC 213 ms
8,072 KB
testcase_13 AC 213 ms
8,304 KB
testcase_14 AC 212 ms
8,024 KB
権限があれば一括ダウンロードができます

ソースコード

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