結果

問題 No.2195 AND Set
ユーザー 👑 kakel-sankakel-san
提出日時 2023-09-02 22:43:31
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 534 ms / 2,000 ms
コード長 1,484 bytes
コンパイル時間 2,354 ms
コンパイル使用メモリ 67,964 KB
実行使用メモリ 54,700 KB
最終ジャッジ日時 2023-09-02 22:43:44
合計ジャッジ時間 13,147 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
22,548 KB
testcase_01 AC 67 ms
24,540 KB
testcase_02 AC 505 ms
46,592 KB
testcase_03 AC 489 ms
49,332 KB
testcase_04 AC 500 ms
48,904 KB
testcase_05 AC 468 ms
50,804 KB
testcase_06 AC 501 ms
48,816 KB
testcase_07 AC 466 ms
46,136 KB
testcase_08 AC 468 ms
48,704 KB
testcase_09 AC 491 ms
46,076 KB
testcase_10 AC 505 ms
52,664 KB
testcase_11 AC 534 ms
50,784 KB
testcase_12 AC 501 ms
54,700 KB
testcase_13 AC 525 ms
50,624 KB
testcase_14 AC 512 ms
50,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var q = NN;
        var query = NArr(q);
        var ans = new List<int>();
        var bits = new int[30];
        var set = new HashSet<int>();
        foreach (var que in query)
        {
            if (que[0] == 1)
            {
                if (set.Add(que[1]))
                {
                    for (var b = 0; b < bits.Length; ++b) bits[b] += (que[1] >> b) & 1;
                }
            }
            else if (que[0] == 2)
            {
                if (set.Remove(que[1]))
                {
                    for (var b = 0; b < bits.Length; ++b) bits[b] -= (que[1] >> b) & 1;
                }
            }
            else
            {
                if (set.Count == 0) ans.Add(-1);
                else
                {
                    var sub = 0;
                    for (var b = 0; b < bits.Length; ++b) if (bits[b] == set.Count) sub += 1 << b;
                    ans.Add(sub);
                }
            }
        }
        WriteLine(string.Join("\n", ans));
    }
}
0