結果

問題 No.2195 AND Set
ユーザー FplusFplusFFplusFplusF
提出日時 2023-01-20 21:34:37
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 451 ms / 2,000 ms
コード長 1,250 bytes
コンパイル時間 1,966 ms
コンパイル使用メモリ 206,764 KB
実行使用メモリ 8,216 KB
最終ジャッジ日時 2023-09-05 13:44:59
合計ジャッジ時間 8,245 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 304 ms
4,380 KB
testcase_03 AC 325 ms
4,904 KB
testcase_04 AC 301 ms
4,380 KB
testcase_05 AC 379 ms
4,884 KB
testcase_06 AC 372 ms
5,136 KB
testcase_07 AC 327 ms
4,376 KB
testcase_08 AC 370 ms
4,880 KB
testcase_09 AC 320 ms
4,376 KB
testcase_10 AC 432 ms
7,920 KB
testcase_11 AC 434 ms
8,048 KB
testcase_12 AC 451 ms
8,216 KB
testcase_13 AC 427 ms
7,976 KB
testcase_14 AC 433 ms
7,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
using ll=long long;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll,ll>;
const ll INF=(1ll<<60);
template<class T> void chmin(T &a,T b){
    if(a>b){
        a=b;
    }
}
template<class T> void chmax(T &a,T b){
    if(a<b){
        a=b;
    }
}
int main(){
    vector<ll> v(30,0);
    set<ll> s;
    ll q;
    cin >> q;
    while(q--){
        ll p;
        cin >> p;
        if(p==1){
            ll x;
            cin >> x;
            if(s.count(x)) continue;
            s.insert(x);
            rep(i,30){
                if(x&(1<<i)){
                    v[i]++;
                }
            }
        }
        if(p==2){
            ll x;
            cin >> x;
            if(!s.count(x)) continue;
            s.erase(x);
            rep(i,30){
                if(x&(1<<i)){
                    v[i]--;
                }
            }
        }
        if(p==3){
            if(s.size()==0) cout << -1 << endl;
            else{
                ll sum=0;
                rep(i,30){
                    if(v[i]==s.size()) sum+=(1<<i);
                }
                cout << sum << endl;
            }
        }
    }
}
0