Cod sursa(job #1798238)

Utilizator andrey2397Barbu Andrei Octavian andrey2397 Data 4 noiembrie 2016 23:43:44
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.95 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

const int mod=666013;

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

int n, i, tip;
long long int x;
vector<int> h[mod];

void adauga(int x)
{
    int rest=x%mod;
    h[rest].push_back(x);
}
void sterge(int x)
{
    int rest=x%mod;
    vector<int>::iterator i;
    for(i=h[rest].begin();i!=h[rest].end();++i){
        if(*i==x){
            *i=-1;
            return;
        }
    }
}
int cauta(int x)
{
    int rest=x%mod, ok=0;
    vector<int>::iterator i;
    for(i=h[rest].begin();i!=h[rest].end();++i){
        if(*i==x){
            ok=1;
            break;
        }
    }
    if(ok==0) return 0;
    else return 1;
}

int main()
{
    fin>>n;
    for(i=1;i<=n;++i){
        fin>>tip>>x;
        if(tip==1) adauga(x);
        else if(tip==2) sterge(x);
        else if(tip==3) fout<<cauta(x)<<"\n";
    }
    return 0;
}