結果

問題 No.2195 AND Set
ユーザー kakel-sankakel-san
提出日時 2023-09-02 22:43:31
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 475 ms / 2,000 ms
コード長 1,484 bytes
コンパイル時間 2,881 ms
コンパイル使用メモリ 112,644 KB
実行使用メモリ 58,076 KB
最終ジャッジ日時 2024-06-12 04:54:55
合計ジャッジ時間 9,565 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 13
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

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