Cod sursa(job #1801084)

Utilizator Mihai_PredaPreda Mihai Dragos Mihai_Preda Data 8 noiembrie 2016 17:28:53
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.94 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

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

const int MOD = 954451;

int n;
vector<int> a[MOD];

bool exista(int x)
{
    int m = x % MOD;
    for(int i = 0; i < a[m].size(); ++i)
        if(a[m][i] == x)
            return true;
    return false;
}

inline void add(int x)
{
    if(!exista(x))
        a[x % MOD].push_back(x);
}

void del(int x)
{
    int m = x % MOD;
    for(int i = 0; i < a[m].size(); ++i)
    {
        if(a[m][i] == x)
        {
            a[m].erase(a[m].begin() + i);
            break;
        }
    }
}

int main()
{
    in >> n;
    int t;
    int x;
    for(int i = 1; i <= n; ++i)
    {
        in >> t;
        in >> x;
        if(t == 1)
            add(x);
        else if(t == 2)
            del(x);
        else
            out << exista(x) << "\n";
    }
    return 0;
}