結果

問題 No.2195 AND Set
ユーザー daiota
提出日時 2023-01-21 02:45:31
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 285 ms / 2,000 ms
コード長 691 bytes
コンパイル時間 1,554 ms
コンパイル使用メモリ 173,956 KB
実行使用メモリ 8,192 KB
最終ジャッジ日時 2024-06-23 14:09:02
合計ジャッジ時間 5,990 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
#define REP(i,n) for(int i=0;i<int(n);i++)

int b[35];

int main(void){
	cin.tie(nullptr);  ios_base::sync_with_stdio(false);


	int Q;
	cin >> Q;
	set<int> s;
	REP(j,Q){
		int q,x;
		cin >> q;

		if(q==1){
			cin >> x;
			if(s.count(x)==1) continue;
			REP(i,31) if(x & (1<<i)) b[i]++;
			s.insert(x);
	    }
		if(q==2 ){
			cin >> x;
			if(s.count(x)==0) continue;
			REP(i,31) if(x & (1<<i)) b[i]--;
			s.erase(x);
		}
		if(q==3){
			int n=s.size(),a=0;
			if(n==0){;
				cout << -1 << endl;
				continue;
			}
			REP(i,31) if(b[i]==n) a+=(1<<i);
			cout << a << endl;
		}

	}



	return 0;
}
0