結果

問題 No.2195 AND Set
ユーザー elphe
提出日時 2024-12-11 17:45:30
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 1,276 bytes
コンパイル時間 912 ms
コンパイル使用メモリ 87,540 KB
最終ジャッジ日時 2025-02-26 12:01:16
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdint>
#include <vector>
#include <unordered_set>
#include <array>
#include <climits>

using namespace std;

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

	uint32_t Q, i, j;
	cin >> Q;
	vector<pair<char, uint32_t>> query(Q);
	for (i = 0; i != Q; ++i)
	{
		cin >> query[i].first;
		if (query[i].first != '3') cin >> query[i].second;
	}

	unordered_set<uint32_t> S;
	array<uint32_t, CHAR_BIT * sizeof(query[0].second)> bitwise_counter;
	uint32_t ans;
	bitwise_counter.fill(UINT32_C(0));
	for (i = 0; i != Q; ++i)
		switch (query[i].first)
		{
		case '1':
			if (S.find(query[i].second) == S.end())
			{
				S.insert(query[i].second);
				for (j = 0; j != bitwise_counter.size(); ++j)
					if ((query[i].second >> j) & UINT32_C(1)) ++bitwise_counter[j];
			}
			break;

		case '2':
			if (S.find(query[i].second) != S.end())
			{
				S.erase(query[i].second);
				for (j = 0; j != bitwise_counter.size(); ++j)
					if ((query[i].second >> j) & UINT32_C(1)) --bitwise_counter[j];
			}
			break;

		case '3':
			if (S.empty()) cout << "-1\n";
			else
			{
				ans = 0;
				for (j = 0; j != bitwise_counter.size(); ++j)
					if (bitwise_counter[j] == S.size()) ans |= UINT32_C(1) << j;
				cout << ans << '\n';
			}
		}

	return 0;
}
0