Cod sursa(job #994220)

Utilizator classiusCobuz Andrei classius Data 5 septembrie 2013 09:44:48
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.88 kb
#include <fstream>
#include <vector>

using namespace std;

ifstream f("hashuri.in");
ofstream g("hashuri.out");

const int M=660013;
vector<int> mp[M];

typedef vector<int>::iterator it;

inline int h(int x){
    return x%M;
}

inline it search(int x){
    int y=h(x);

    for(it i=mp[y].begin();i!=mp[y].end();i++)
        if(*i==x)
            return i;
    return mp[y].end();
}

void add(int x){
    int y=h(x);
    if(search(x) != mp[y].end()) return;
    mp[y].push_back(x);
    return;
}

void erase(int x){
    it ax=search(x);
    if(ax==mp[h(x)].end()) return;
    mp[h(x)].erase(ax);
    return;
}

int main()
{
    int n;
    f>>n;

    for(int i=1;i<=n;i++){
        int op,x;
        f>>op>>x;

        switch(op){
            case 1:add(x); break;
            case 2:erase(x); break;
            case 3:g<<( search(x) != mp[h(x)].end() )<<'\n'; break;
       }
    }

    return 0;
}