結果

問題 No.2195 AND Set
ユーザー ripityripity
提出日時 2023-01-20 21:47:01
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 296 ms / 2,000 ms
コード長 1,199 bytes
コンパイル時間 3,282 ms
コンパイル使用メモリ 225,152 KB
実行使用メモリ 8,208 KB
最終ジャッジ日時 2023-09-05 14:01:49
合計ジャッジ時間 8,070 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 174 ms
4,412 KB
testcase_03 AC 210 ms
5,236 KB
testcase_04 AC 175 ms
4,380 KB
testcase_05 AC 258 ms
4,896 KB
testcase_06 AC 259 ms
4,924 KB
testcase_07 AC 215 ms
4,376 KB
testcase_08 AC 261 ms
4,956 KB
testcase_09 AC 202 ms
4,380 KB
testcase_10 AC 289 ms
8,056 KB
testcase_11 AC 289 ms
8,004 KB
testcase_12 AC 294 ms
8,208 KB
testcase_13 AC 296 ms
8,064 KB
testcase_14 AC 291 ms
8,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int Q;
    cin >> Q;
    set<int> S;
    vector<vector<int>> cnt(30, vector<int>(2));
    for( int q = 0; q < Q; q++ ) {
        int t, x;
        cin >> t;
        if( t == 1 ) {
            cin >> x;
            if( !S.count(x) ) {
                S.insert(x);
                for( int i = 0; i < 30; i++ ) {
                    cnt[i][(x>>i)&1]++;
                }
            }
        }else if( t == 2 ) {
            cin >> x;
            if( S.count(x) ) {
                S.erase(x);
                for( int i = 0; i < 30; i++ ) {
                    cnt[i][(x>>i)&1]--;
                }
            }
        }else {
            if( S.empty() ) {
                cout << -1 << endl;
            }else {
                int ans = 0;
                for( int i = 0; i < 30; i++ ) {
                    if( cnt[i][0] == 0 && cnt[i][1] > 0 ) {
                        ans |= 1<<i;
                    }
                }
                cout << ans << endl;
            }
        }
    }
}
0