結果
問題 | No.2195 AND Set |
ユーザー |
![]() |
提出日時 | 2024-05-06 14:42:57 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 215 ms / 2,000 ms |
コード長 | 1,288 bytes |
コンパイル時間 | 1,909 ms |
コンパイル使用メモリ | 201,508 KB |
最終ジャッジ日時 | 2025-02-21 11:25:19 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 13 |
ソースコード
#include <bits/stdc++.h>using namespace std;void fast_io() {ios_base::sync_with_stdio(false);cin.tie(nullptr);}int main() {fast_io();int q;cin >> q;set<int> st;vector<int> cnt(30);for (; q--;) {int type;cin >> type;if (type == 1) {int x;cin >> x;if (st.find(x) == st.end()) {st.insert(x);for (int i = 0; i < 30; i++) {if (x & (1 << i)) {cnt[i]++;}}}} else if (type == 2) {int x;cin >> x;if (st.find(x) != st.end()) {st.erase(x);for (int i = 0; i < 30; i++) {if (x & (1 << i)) {cnt[i]--;}}}} else {if (st.empty()) {cout << -1 << "\n";} else {int ans = 0;for (int i = 0; i < 30; i++) {if (cnt[i] == st.size()) {ans += 1 << i;}}cout << ans << "\n";}}}}