結果

問題 No.2195 AND Set
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-05-05 10:00:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 532 ms / 2,000 ms
コード長 1,135 bytes
コンパイル時間 1,050 ms
コンパイル使用メモリ 115,644 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2024-05-02 07:56:08
合計ジャッジ時間 8,509 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 292 ms
5,376 KB
testcase_03 AC 322 ms
5,376 KB
testcase_04 AC 295 ms
5,376 KB
testcase_05 AC 352 ms
5,376 KB
testcase_06 AC 347 ms
5,376 KB
testcase_07 AC 311 ms
5,376 KB
testcase_08 AC 357 ms
5,376 KB
testcase_09 AC 310 ms
5,376 KB
testcase_10 AC 532 ms
8,064 KB
testcase_11 AC 382 ms
8,064 KB
testcase_12 AC 395 ms
7,936 KB
testcase_13 AC 401 ms
8,064 KB
testcase_14 AC 407 ms
8,064 KB
権限があれば一括ダウンロードができます

ソースコード

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