結果
問題 | No.2195 AND Set |
ユーザー |
![]() |
提出日時 | 2023-01-21 07:07:57 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 693 ms / 2,000 ms |
コード長 | 1,455 bytes |
コンパイル時間 | 815 ms |
コンパイル使用メモリ | 110,512 KB |
実行使用メモリ | 35,608 KB |
最終ジャッジ日時 | 2024-06-23 17:22:37 |
合計ジャッジ時間 | 12,164 ms |
ジャッジサーバーID (参考情報) |
judge1 / 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.
ソースコード
using static System.Math; using System.Collections.Generic; using System.Linq; using System; public class Hello { static void Main() { var q = int.Parse(Console.ReadLine().Trim()); getAns(q); } static void getAns(int q) { var b = new int[30]; var hs = new HashSet<int>(); for (int i = 0; i < q; i++) { string[] line = Console.ReadLine().Trim().Split(' '); if (line[0] == "1") { var x = int.Parse(line[1]); if (hs.Add(x)) { for (int j = 0; j < 30; j++) { if (((x >> j) & 1) == 1) b[j]++; } } } else if (line[0] == "2") { var x = int.Parse(line[1]); if (hs.Remove(x)) { for (int j = 0; j < 30; j++) { if (((x >> j) & 1) == 1) b[j]--; } } } else { var hsc = hs.Count; if (hsc == 0) { Console.WriteLine(-1); continue; } var ans = 0; for (int j = 0; j < 30; j++) { if (b[j] == hsc) ans |= 1 << j; } Console.WriteLine(ans); } } } }