結果
問題 | No.2195 AND Set |
ユーザー | tenten |
提出日時 | 2023-01-25 12:57:02 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 1,185 ms / 2,000 ms |
コード長 | 2,831 bytes |
コンパイル時間 | 4,441 ms |
コンパイル使用メモリ | 87,228 KB |
実行使用メモリ | 76,736 KB |
最終ジャッジ日時 | 2023-09-09 01:00:12 |
合計ジャッジ時間 | 21,534 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
49,540 KB |
testcase_01 | AC | 42 ms
49,384 KB |
testcase_02 | AC | 917 ms
68,776 KB |
testcase_03 | AC | 1,102 ms
76,328 KB |
testcase_04 | AC | 970 ms
70,604 KB |
testcase_05 | AC | 1,094 ms
72,140 KB |
testcase_06 | AC | 1,121 ms
72,320 KB |
testcase_07 | AC | 615 ms
60,888 KB |
testcase_08 | AC | 866 ms
72,356 KB |
testcase_09 | AC | 672 ms
60,820 KB |
testcase_10 | AC | 1,125 ms
76,516 KB |
testcase_11 | AC | 985 ms
76,492 KB |
testcase_12 | AC | 1,090 ms
76,736 KB |
testcase_13 | AC | 1,127 ms
76,436 KB |
testcase_14 | AC | 1,185 ms
76,512 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int q = sc.nextInt(); StringBuilder sb = new StringBuilder(); int[] counts = new int[30]; HashSet<Integer> exists = new HashSet<>(); while (q-- > 0) { int type = sc.nextInt(); if (type == 1) { int x = sc.nextInt(); if (exists.contains(x)) { continue; } for (int i = 0; i < 30; i++) { if ((x & (1 << i)) > 0) { counts[i]++; } } exists.add(x); } else if (type == 2) { int x = sc.nextInt(); if (!exists.contains(x)) { continue; } for (int i = 0; i < 30; i++) { if ((x & (1 << i)) > 0) { counts[i]--; } } exists.remove(x); } else { if (exists.size() == 0) { sb.append("-1\n"); continue; } int ans = 0; for (int i = 0; i < 30; i++) { if (counts[i] == exists.size()) { ans += (1 << i); } } sb.append(ans).append("\n"); } } System.out.print(sb); } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }