結果

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;
using ll = long long;

int main(){

    int Q, t, x, S;
    cin >> Q;
    vector<int> cnt(30);
    set<int> st;

    while(Q){
        Q--;
        cin >> t;
        if (t == 1){
            cin >> x;
            if (st.count(x)) continue;
            st.insert(x);
            for (int i=0; i<30; i++){
                if (x & (1<<i)) cnt[i]++;
            }
        }
        else if (t == 2){
            cin >> x;
            if (!st.count(x)) continue;
            st.erase(x);
            for (int i=0; i<30; i++){
                if (x & (1<<i)) cnt[i]--;
            }
        }
        else{
            if (st.size() == 0){
                cout << -1 << endl;
                continue;
            }
            S = 0;
            for (int i=0; i<30; i++){
                if (cnt[i] == st.size()) S += 1<<i;
            }
            cout << S << endl;
        }
    }

    return 0;
}
0