Cod sursa(job #922296)

Utilizator iulianpopescu13Iulian Popescu iulianpopescu13 Data 22 martie 2013 02:38:54
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.08 kb
# include <fstream>
# include <vector>
# define mod 666013
using namespace std;
int n;
vector< vector< int > > mat ( mod);
inline vector<int>::iterator find_value( int x )
{
    int list = x % mod;
    vector<int>::iterator it;
    for (it = mat[ list ].begin(); it != mat[ list ].end(); ++it )
        if ( *it == x )
            return it;
    return mat[ list ].end();
}
inline void insert_value( int x )
{
    int list = x % mod;    
    if ( find_value( x ) == mat[ list ].end() )
        mat[ list ].push_back(x);
}
inline void erase_value(int x)
{
    int list = x % mod;
    vector<int>::iterator it = find_value(x);
    if ( it != mat[ list ].end() )
        mat[ list ].erase(it);
}
int main()
{
    ifstream fin("hashuri.in");
    ofstream fout("hashuri.out");
	fin >> n;
    for( ; n; --n )
    {
		int op, x;
        fin >> op >> x;
        if (op == 1) 
            insert_value(x);
		else
			if (op == 2) 
				erase_value(x);
			else
				if(op == 3 && find_value(x) != mat[ x % mod ].end() )
					fout <<"1\n";
				else
					fout <<"0\n";
    }
}