結果

問題 No.2195 AND Set
ユーザー mushilymushily
提出日時 2023-03-16 09:57:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 442 ms / 2,000 ms
コード長 1,148 bytes
コンパイル時間 676 ms
コンパイル使用メモリ 73,904 KB
実行使用メモリ 8,336 KB
最終ジャッジ日時 2023-10-18 12:55:43
合計ジャッジ時間 6,929 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 306 ms
4,460 KB
testcase_03 AC 328 ms
5,228 KB
testcase_04 AC 300 ms
4,460 KB
testcase_05 AC 375 ms
5,224 KB
testcase_06 AC 370 ms
5,224 KB
testcase_07 AC 326 ms
4,348 KB
testcase_08 AC 364 ms
5,224 KB
testcase_09 AC 314 ms
4,348 KB
testcase_10 AC 431 ms
8,332 KB
testcase_11 AC 433 ms
8,332 KB
testcase_12 AC 435 ms
8,336 KB
testcase_13 AC 433 ms
8,332 KB
testcase_14 AC 442 ms
8,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <set>

using namespace std;
int main()
{
    unsigned int q, i, t;
    int j;
    long x;
    unsigned int c[31] = {0};
    set<long> s;
    cin >> q;
    for (i = 0; i < q; i++)
    {
        cin >> t;
        switch (t)
        {
        case 1:
            cin >> x;
            if (s.count(x) == 0)
            {
                s.insert(x);
                for (j = 0; j < 31; j++)
                    if ((1 << j) & x)
                        c[j]++;
            }
            break;
        case 2:
            cin >> x;
            if (s.count(x) != 0)
            {
                s.erase(x);
                for (j = 0; j < 31; j++)
                    if ((1 << j) & x)
                        c[j]--;
            }
            break;

        default:
            if (s.size() > 0)
            {
                x=0;
                for(j=30;j>=0;j--)
                {
                    x=x<<1;
                    if(c[j]==s.size())
                        x++;
                }
            }
            else
                x = -1;
            cout << x << endl;
            break;
        }
    }
}
0