結果
問題 | No.2195 AND Set |
ユーザー |
|
提出日時 | 2023-03-05 16:13:46 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 185 ms / 2,000 ms |
コード長 | 1,217 bytes |
コンパイル時間 | 1,432 ms |
コンパイル使用メモリ | 175,780 KB |
実行使用メモリ | 8,192 KB |
最終ジャッジ日時 | 2024-09-18 01:36:43 |
合計ジャッジ時間 | 5,300 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 13 |
ソースコード
#include <bits/stdc++.h>using namespace std;int main() {ios::sync_with_stdio(false);cin.tie(nullptr);int Q;cin >> Q;vector<int> bit(30, 0);set<int> S;while (Q--) {int t;cin >> t;if (t == 1) {int x;cin >> x;if (S.find(x) == S.end()) {S.insert(x);for (int i = 0; i < 30; i++) {if ((x >> i) & 1) {bit[i]++;}}}} else if (t == 2) {int x;cin >> x;if (S.find(x) != S.end()) {S.erase(x);for (int i = 0; i < 30; i++) {if ((x >> i) & 1) {bit[i]--;}}}} else {if (S.size() == 0) {cout << -1 << '\n';continue;}int ans = 0;for (int i = 0; i < 30; i++) {if ((int) S.size() == bit[i]) {ans += (1 << i);}}cout << ans << '\n';}}}