Cod sursa(job #966818)

Utilizator dropsdrop source drops Data 26 iunie 2013 16:47:28
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.06 kb
#include <iostream>
#include <fstream>
#include <cmath>
#include <vector>
#include <queue>
#include <deque>
#include <list>
#include <ctime>
#include <string>
#include <algorithm>
using namespace std;
ifstream ff("hashuri.in");
ofstream gg("hashuri.out");
#define md 19007
vector<int> cc[32][md];

int bit(int x){
	int n=0;
	while(x>0){n++; x-=x&-x;}
	return n;
}

bool eok(int k,int p, int x){
	int l=cc[k][p].size();
	for(int i=0;i<l;i++)
	if(cc[k][p][i]==x)return 1;
	return 0;
}

void add(int k,int p, int x){
	int l=cc[k][p].size(), w=-1;
	for(int i=0;i<l;i++)
	if(cc[k][p][i]==x)return; else
	if(cc[k][p][i]==-1)w=i;
	if(w!=-1) cc[k][p][w]=x; else cc[k][p].push_back(x);
}

void rem(int k,int p,int x){
	int l=cc[k][p].size();
	for(int i=0;i<l;i++)
	if(cc[k][p][i]==x){ cc[k][p][i]=-1; return; }
}

int main(){
	int n, op, x, k, p;
	ff >> n;
	for(int i=1;i<=n;i++){
		ff >> op >> x;
		k=bit(x);
		p=x%md;
		if(op==1){ add(k,p,x); } else
		if(op==2){ rem(k,p,x); } else
		if(op==3){ gg << eok(k,p,x) << "\n"; }
	}
	return 0;
}