結果

問題 No.2195 AND Set
ユーザー V_MelvilleV_Melville
提出日時 2023-01-20 22:51:15
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 444 ms / 2,000 ms
コード長 1,123 bytes
コンパイル時間 2,922 ms
コンパイル使用メモリ 250,692 KB
実行使用メモリ 8,032 KB
最終ジャッジ日時 2023-09-05 15:16:53
合計ジャッジ時間 9,361 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 301 ms
4,376 KB
testcase_03 AC 329 ms
5,056 KB
testcase_04 AC 299 ms
4,376 KB
testcase_05 AC 373 ms
5,040 KB
testcase_06 AC 372 ms
4,956 KB
testcase_07 AC 329 ms
4,380 KB
testcase_08 AC 367 ms
4,936 KB
testcase_09 AC 314 ms
4,376 KB
testcase_10 AC 435 ms
8,032 KB
testcase_11 AC 433 ms
8,020 KB
testcase_12 AC 435 ms
8,020 KB
testcase_13 AC 434 ms
8,028 KB
testcase_14 AC 444 ms
8,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

int main() {
    int q;
    cin >> q;
    
    set<int> st;
    const int M = 30;
    vector<int> cnt(M);
    int ans = 0;
    rep(qi, q) {
        int type;
        cin >> type;
        if (type == 3) {
            if (!st.size()) cout << -1 << '\n';
            else {
                int ans = 0;
                rep(i, M) {
                    if (cnt[i] == int(st.size())) ans += 1<<i;
                }
                cout << ans << '\n';
            }
        }
        else {
            int x;
            cin >> x;
            if (type == 1) {
                if (st.count(x)) continue;
                st.insert(x);
                rep(i, M) {
                    if (x>>i&1) cnt[i]++;
                }
            }
            else {
                if (!st.count(x)) continue;
                st.erase(x);
                rep(i, M) if (x>>i&1) cnt[i]--;
            }
            // rep(i, M) cerr << cnt[i] << " \n"[i == M-1];
        }
        
        // cerr << st.size() << '\n';
    }
    
    return 0;
}
0