Cod sursa(job #1604634)

Utilizator tudormaximTudor Maxim tudormaxim Data 18 februarie 2016 14:03:10
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.03 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

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

const int mod = 666013;
vector <int> h[mod];

vector <int> :: iterator ok(int val, int poz)
{
    vector <int> :: iterator it;
    for(it=h[poz].begin(); it!=h[poz].end(); it++)
        if(*it==val) return it;
    return it;
}

void add(int val, int poz)
{
    if(ok(val, poz)==h[poz].end())
        h[poz].push_back(val);
}

void del(int val, int poz)
{
    vector <int> :: iterator it=ok(val, poz);
    if(it!=h[poz].end())
        h[poz].erase(it);
}

int main()
{
    ios_base::sync_with_stdio(false);
    int n, op, i, x, poz;
    fin >> n;
    for(i=1; i<=n; i++)
    {
        fin >> op >> x;
        poz=x%mod;
        if(op==1) add(x, poz);
        if(op==2) del(x, poz);
        if(op==3)
        {
            if(ok(x, poz)!=h[poz].end()) fout << "1\n";
            else fout << "0\n";
        }
    }
    fin.close();
    fout.close();
    return 0;
}