結果

問題 No.2195 AND Set
ユーザー nono00
提出日時 2023-01-21 00:40:27
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 419 ms / 2,000 ms
コード長 1,276 bytes
コンパイル時間 1,868 ms
コンパイル使用メモリ 199,360 KB
最終ジャッジ日時 2025-02-10 06:03:29
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

void solve() {
    int q;
    cin >> q;
    array<int, 30> bit;
    bit.fill(0);
    set<int> s;

    for (int i = 0; i < q; i++) {
        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 {
            int ans = 0;
            for (int i = 0; i < 30; i++) {
                if (s.size() == bit[i]) {
                    ans |= (1 << i);
                }
            }
            if (s.size() == 0) {
                cout << -1 << '\n';
            } else {
                cout << ans << '\n';
            }
        }
    }
}

int main() {
    int q = 1;
    // cin >> q;
    while (q--) {
        solve();
    }
}
0