結果

問題 No.2195 AND Set
ユーザー t98slidert98slider
提出日時 2023-01-20 21:59:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 238 ms / 2,000 ms
コード長 935 bytes
コンパイル時間 1,585 ms
コンパイル使用メモリ 171,732 KB
実行使用メモリ 8,152 KB
最終ジャッジ日時 2023-09-05 14:17:45
合計ジャッジ時間 5,264 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 127 ms
4,376 KB
testcase_03 AC 159 ms
4,836 KB
testcase_04 AC 126 ms
4,376 KB
testcase_05 AC 142 ms
4,908 KB
testcase_06 AC 140 ms
4,976 KB
testcase_07 AC 99 ms
4,376 KB
testcase_08 AC 139 ms
4,940 KB
testcase_09 AC 88 ms
4,376 KB
testcase_10 AC 236 ms
8,152 KB
testcase_11 AC 238 ms
8,052 KB
testcase_12 AC 236 ms
8,016 KB
testcase_13 AC 237 ms
8,076 KB
testcase_14 AC 234 ms
7,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int Q, cmd, x;
    cin >> Q;
    vector<int> cnt(30);
    set<int> S;
    while(Q--){
        cin >> cmd;
        if(cmd <= 2)cin >> x;
        if(cmd == 1){
            if(S.count(x))continue;
            S.insert(x);
            for(int i = 0; i < 30; i++){
                if(x >> i & 1) cnt[i]++;
            }
        }else if(cmd == 2){
            if(!S.count(x))continue;
            S.erase(x);
            for(int i = 0; i < 30; i++){
                if(x >> i & 1) cnt[i]--;
            }
        }else{
            if(S.empty()){
                cout << -1 << '\n';
                continue;
            }
            int ans = 0;
            for(int i = 0; i < 30; i++){
                if(cnt[i] == S.size())ans |= 1 << i;
            }
            cout << ans << '\n';
        }
    }
}
0