Cod sursa(job #2059641)

Utilizator woogiefanBogdan Stanciu woogiefan Data 7 noiembrie 2017 12:41:12
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.91 kb
#include <iostream>
#include <fstream>
#include <vector>
#define mod 666013

using namespace std;

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

int n;
vector <int> v[mod];
int op;
int x;

int _find(int value)
{
    int poz = value % mod;
    for(int i = 0 ; i < v[poz].size() ; i++) if(v[poz][i] == value) return i;
    return -1;
}

void _insert(int value)
{
    int poz = value % mod;
    v[poz].push_back(value);
}

void _delete(int poz , int value)
{
    swap(v[poz][value],v[poz][v[poz].size()-1]);
    v[poz].pop_back();
}

int main()
{
    fin >> n;
    for(int i = 1 ; i <= n ; ++i)
    {
        fin >> op >> x;
        if(op == 1 && _find(x) == -1) _insert(x);
        if(op == 2 && _find(x) != -1) _delete(x % mod , _find(x));
        if(op == 3)
            if(_find(x) == -1) fout << 0 << '\n';
            else fout << 1 << '\n';

    }
    return 0;
}