結果

問題 No.2195 AND Set
ユーザー MAHAYANAMAHAYANA
提出日時 2023-11-03 06:08:50
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 460 ms / 2,000 ms
コード長 1,158 bytes
コンパイル時間 4,744 ms
コンパイル使用メモリ 249,112 KB
実行使用メモリ 8,252 KB
最終ジャッジ日時 2023-11-03 06:09:04
合計ジャッジ時間 13,215 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 309 ms
4,376 KB
testcase_03 AC 336 ms
5,144 KB
testcase_04 AC 334 ms
4,376 KB
testcase_05 AC 374 ms
5,144 KB
testcase_06 AC 374 ms
5,144 KB
testcase_07 AC 351 ms
4,348 KB
testcase_08 AC 367 ms
5,140 KB
testcase_09 AC 318 ms
4,348 KB
testcase_10 AC 438 ms
8,248 KB
testcase_11 AC 424 ms
8,252 KB
testcase_12 AC 416 ms
8,252 KB
testcase_13 AC 460 ms
8,248 KB
testcase_14 AC 429 ms
8,252 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,m,n) for(int i=m; i<n; ++i)
#define repl(i,m,n) for(ll i=m; i<n; ++i)

int main(){
    multiset<int> st;
    vector<int> cnt(30,0);

    int Q;
    cin >> Q;

    rep(q, 0, Q){
        int type;
        cin >> type;

        if(type == 1){
            int x;
            cin >> x;
            if(st.find(x) != st.end()) continue;
            st.insert(x);
            rep(i, 0, 30){
                if(x & (1<<i)) cnt[i]++;
            }
        }else if(type == 2){
            int x;
            cin >> x;
            auto itr = st.find(x);
            if(itr == st.end()) continue;
            st.erase(itr);
            rep(i, 0, 30){
                if(x & (1<<i)) cnt[i]--;
            }
        }else{
            int ans = 0;
            int sz = st.size();
            if(sz == 0){
                cout << -1 << endl;
            }else{
                rep(i, 0, 30){
                    if(cnt[i] == sz){
                        ans += (1<<i);
                    }
                }
                cout << ans << endl;
            }
        }
    }

    return 0;
}
0