Cod sursa(job #2289780)

Utilizator FrequeAlex Iordachescu Freque Data 25 noiembrie 2018 11:43:00
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.5 kb
#include <bits/stdc++.h>
#define ios ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define enter cout << '\n'

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <pii> vii;
typedef vector <ll> vl;
typedef vector <pll> vll;
typedef queue <int> qi;
typedef queue <pii> qii;
typedef queue <ll> ql;
typedef queue <pll> qll;

const int INF = SHRT_MAX - 2;
const int MOD = 100019;
const int EPSILON = 0.0000000001;
const short NMAX = 4000 + 5;
const short VMAX = 8000 + 5;

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

vector <int> Hash[MOD];

int findH(int x)
{
    int xmod = x % MOD;
    for (int i = 0; i < Hash[xmod].size(); ++i)
        if (Hash[xmod][i] == x)
            return i;
    return -1;
}

void insertH(int x)
{
    if (findH(x) == -1) Hash[x % MOD].pb(x);
}

void deleteH(int x)
{
    int xmod = x % MOD;
    int f = findH(x);
    if (f >= 0)
    {
        swap(Hash[xmod][f], Hash[xmod][Hash[xmod].size() - 1]);
        Hash[xmod].pop_back();
    }
}

int main()
{
    int op;
    fin >> op;
    while (op--)
    {
        int cod, x;
        fin >> cod >> x;
        if (cod == 1) insertH(x);
        else if (cod == 2) deleteH(x);
        else if (findH(x) == -1) fout << "0\n";
        else fout << "1\n";
    }

    return 0;
}

/*
6 90
3 5 12 22 37 48
*/