結果
| 問題 |
No.2195 AND Set
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-07-18 18:56:32 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 393 ms / 2,000 ms |
| コード長 | 2,623 bytes |
| コンパイル時間 | 859 ms |
| コンパイル使用メモリ | 106,604 KB |
| 最終ジャッジ日時 | 2025-02-15 15:38:18 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 13 |
ソースコード
#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
#include<tuple>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<ll,ll> P;
typedef pair<int,P> PP;
const ll MOD=1e9+7;
int main(){
int Q;
cin>>Q;
vector<int> ans(31,0);
vector<int> digit(31,0);//2進数で見た際にstにあるなかで最高桁はいくつか
set<int> st;
vector<int> c;
for(int q=0;q<Q;q++){
int t;
cin>>t;
if(t==1){
int x;
cin>>x;
if(!st.count(x)){
st.insert(x);
{
for(int i=0;i<=30;i++){
if(((x>>i)&1)==0){
ans[i]++;
}
}
}
{
int i=0;
while(x>0){
/*
if(((x>>i)&1)==0){
//xの2^i桁目が0ならカウント
ans[i]++;
}
*/
digit[i]++;
i++;
x/=2;
}
}
}
}else if(t==2){
int x;
cin>>x;
if(st.count(x)){
{
for(int i=0;i<=30;i++){
if(((x>>i)&1)==0){
ans[i]--;
}
}
}
st.erase(x);
int i=0;
while(x>0){
/*
if(((x>>i)&1)==0){
//xの2^i桁目が0ならカウント
ans[i]--;
}
*/
digit[i]--;
i++;
x/=2;
}
}
}else{
//t==3
int output=0;
if(st.size()==0){
output=-1;
}else{
for(int i=0;i<=30;i++){
if(digit[i]==0)break;
if(ans[i]==0){
output|=1<<i;
}
}
}
c.push_back(output);
//cout<<output<<endl;
}
}
for(int v:c){
cout<<v<<endl;
}
}