Cod sursa(job #1402715)

Utilizator bpalaniciPalanici Bogdan bpalanici Data 26 martie 2015 19:09:23
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1 kb
#include <bits/stdc++.h>

using namespace std;

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

const int MOD = 999983;
vector <int> hash1[MOD];
vector <int>:: iterator it;

int x, op, n;

bool gas(int x, int poz)
{
    for(it = hash1[poz].begin(); it != hash1[poz].end(); it++)
        if (*it == x) return true;
    return false;
}

void o1(int x)
{
    int mod = x % MOD;
    if (!gas(x, x % MOD))
    hash1[mod].push_back(x);
}

void o2(int x)
{
    int mod = x % MOD;
    for (it = hash1[mod].begin(); it != hash1[mod].end(); it++)
        if (*it == x)
        {
            *it = hash1[mod].back();
            hash1[mod].pop_back();
            return;
        }
}

void o3(int x)
{
    if (gas(x, x % MOD)) fout << "1";
    else fout << "0";
    fout << "\n";
}

int main()
{
    fin >> n;
    for (; n; n--)
    {
        fin >> op >> x;
        if (op == 1) {o1(x); continue;}
        else if (op == 2) {o2(x); continue;}
        o3(x);
    }
}