結果

問題 No.2195 AND Set
ユーザー Manuel1024Manuel1024
提出日時 2023-01-20 21:31:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 424 ms / 2,000 ms
コード長 1,099 bytes
コンパイル時間 815 ms
コンパイル使用メモリ 99,204 KB
実行使用メモリ 8,152 KB
最終ジャッジ日時 2023-09-05 13:41:00
合計ジャッジ時間 6,921 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 301 ms
4,376 KB
testcase_03 AC 329 ms
4,956 KB
testcase_04 AC 300 ms
4,500 KB
testcase_05 AC 372 ms
4,960 KB
testcase_06 AC 374 ms
4,960 KB
testcase_07 AC 325 ms
4,376 KB
testcase_08 AC 368 ms
4,896 KB
testcase_09 AC 319 ms
4,376 KB
testcase_10 AC 421 ms
7,980 KB
testcase_11 AC 419 ms
8,152 KB
testcase_12 AC 424 ms
8,008 KB
testcase_13 AC 417 ms
8,048 KB
testcase_14 AC 419 ms
7,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <deque>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
using ll = long long;
using ld = long double;

int main(){
    int q; cin >> q;
    set<int> s;
    vector<int> cnt(32, 0);
    while(q--){
        int op; cin >> op;
        if(op == 1){
            int x; cin >> x;
            if(s.count(x) == 0){
                s.emplace(x);
                for(int i = 30; i >= 0; i--){
                    if((x >> i) & 1) cnt[i]++;
                }
            }
        }else if(op == 2){
            int x; cin >> x;
            if(s.count(x) == 1){
                s.erase(x);
                for(int i = 30; i >= 0; i--){
                    if((x >> i) & 1) cnt[i]--;
                }
            }
        }else{
            int ans = 0;
            for(int i = 30; i >= 0; i--){
                if(cnt[i] == s.size()) ans |= 1 << i;
            }
            if(s.size() == 0) ans = -1;
            cout << ans << '\n';
        }
    }
    return 0;
}
0