Cod sursa(job #809643)

Utilizator Theorytheo .c Theory Data 8 noiembrie 2012 19:24:31
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.07 kb
#include<fstream>
#include<vector>
#define mod 666013
#define nmax 1000009
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");

int N;
vector <int> G[mod];
int cauta(int x)
{
    int R = x % mod;
    for(int i = 0; i < G[R].size(); i++)
        if(G[R][i] == x)
            return i;

    return -1;

}
void add(int x)
{
    if(cauta(x) == -1)
     G[x % mod].push_back(x);

}
void sterge(int x)
{
    int gasit = cauta(x);
    int R = x % mod;
    if(gasit != -1)
    {
        int poz = G[R].size() - 1;
        G[R][gasit] = G[R][poz];
        G[R].pop_back();


    }
}
int main()
{
    fin >> N;
    for(int i = 1; i <= N; i++)
    {
        int type;
        int x;
        fin >> type >> x;
        switch(type)
        {
            case 1: add(x);break;
            case 2: sterge(x);break;
            case 3:
            if(cauta(x) == -1)
                fout << 0;
                    else
                fout << 1;
            fout << '\n';

        }

    }
    fin.close();
    return 0;
}