結果

問題 No.2195 AND Set
ユーザー HIcoderHIcoder
提出日時 2023-07-18 18:56:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 480 ms / 2,000 ms
コード長 2,623 bytes
コンパイル時間 3,198 ms
コンパイル使用メモリ 110,736 KB
実行使用メモリ 8,432 KB
最終ジャッジ日時 2023-10-18 22:12:38
合計ジャッジ時間 11,813 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 317 ms
4,560 KB
testcase_03 AC 357 ms
5,328 KB
testcase_04 AC 325 ms
4,560 KB
testcase_05 AC 392 ms
5,516 KB
testcase_06 AC 392 ms
5,516 KB
testcase_07 AC 334 ms
4,368 KB
testcase_08 AC 386 ms
5,324 KB
testcase_09 AC 327 ms
4,348 KB
testcase_10 AC 474 ms
8,428 KB
testcase_11 AC 474 ms
8,432 KB
testcase_12 AC 480 ms
8,432 KB
testcase_13 AC 471 ms
8,428 KB
testcase_14 AC 469 ms
8,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
#include<tuple>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<ll,ll> P;
typedef pair<int,P> PP;
const ll MOD=1e9+7;


int main(){
    int Q;
    cin>>Q;

    vector<int> ans(31,0);
    vector<int> digit(31,0);//2進数で見た際にstにあるなかで最高桁はいくつか

    set<int> st;

    vector<int> c;

    for(int q=0;q<Q;q++){
        int t;
        cin>>t;
        
        if(t==1){
            int x;
            cin>>x;    
            if(!st.count(x)){
                st.insert(x);

                {
                    for(int i=0;i<=30;i++){
                        if(((x>>i)&1)==0){
                            ans[i]++;
                        }
                    }
                }

                {
                    int i=0;
                    while(x>0){
                        /*
                        if(((x>>i)&1)==0){
                            //xの2^i桁目が0ならカウント
                            ans[i]++;
                        }
                        */
                        digit[i]++;

                        i++;
                        x/=2;
                    }

                }
               
            }

        }else if(t==2){
            int x;
            cin>>x;    

            if(st.count(x)){

                {
                    for(int i=0;i<=30;i++){
                        if(((x>>i)&1)==0){
                            ans[i]--;
                        }
                    }
                }
                
                st.erase(x);
                int i=0;
                while(x>0){
                    /*
                    if(((x>>i)&1)==0){
                        //xの2^i桁目が0ならカウント
                        ans[i]--;
                    }
                    */
                    digit[i]--;

                    i++;
                    x/=2;
                }
            }


        }else{
            //t==3

            

            int output=0;
            
            if(st.size()==0){
                output=-1;   
            }else{
                for(int i=0;i<=30;i++){
                    if(digit[i]==0)break;
                    if(ans[i]==0){
                        output|=1<<i;
                    }
                }

            }
            c.push_back(output);
            //cout<<output<<endl;

        }
    }

    for(int v:c){
        cout<<v<<endl;
    }
}
0